After I signin ior signout using a Google account I’m redirected automatically to http://localhost:3000/users - there is no provision in Mosh’s code for showing a page with users.
Any ideas how to resolve this?
After I signin ior signout using a Google account I’m redirected automatically to http://localhost:3000/users - there is no provision in Mosh’s code for showing a page with users.
Any ideas how to resolve this?
I have fixed it by specifying a redirect in callbacks in NextAuthOptions, redirecting after login/logout to the dashboard page. The code looks like this:
const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!
})
],
session: {
strategy: 'jwt'
},
callbacks: {
async redirect({url, baseUrl}) {
return baseUrl + '/';
}
}
};
Thank you for sharing your solution. I noticed this behavior as soon as I added middleware.ts
with
export { default } from 'next-auth/middleware';
export const config = { matcher: ['/users/:id*'] };
, and re-ran the app. I still have no idea why or how the middleware would be causing the redirect to /users
after login and signout…can’t find anything in the documentation that would suggest why this would occur…