Custom login page in nextAuth
Unanswered
kubas posted this in #help-forum
kubasOP
Hi! I am making a login system in nextjs using nextAuth. I made a custom login and register page, but my middleware keeps trying to redirect me to the
My middleware has only one line of code:
In api/auth/[...nextauth] in authOptions I added this:
Anyone know how to change it? Thanks you
/api/auth/signin page when I'm not logged in. I want it to redirect me to the /login page.My middleware has only one line of code:
export { default } from "next-auth/middleware";In api/auth/[...nextauth] in authOptions I added this:
export const authOptions: AuthOptions = {
pages: {
signIn: "/login",
newUser: "/register",
},
// the rest of the code
}Anyone know how to change it? Thanks you
8 Replies
Thrianta
i had the same error, deleting middleware.ts fixed it for me, for some reason it was redirecting to
/api/auth/...kubasOP
But I want the middleware to work and redirect me to /login. I want this page to be protected with login.
@kubas Hi! I am making a login system in nextjs using nextAuth. I made a custom login and register page, but my middleware keeps trying to redirect me to the `/api/auth/signin` page when I'm not logged in. I want it to redirect me to the `/login` page.
My middleware has only one line of code:
ts
export { default } from "next-auth/middleware";
In api/auth/[...nextauth] in authOptions I added this:
tsx
export const authOptions: AuthOptions = {
pages: {
signIn: "/login",
newUser: "/register",
},
// the rest of the code
}
Anyone know how to change it? Thanks you
I had the same issue. Where is your
[...nextauth] located exactly? So the whole path from your project's root folder.@ncls. I had the same issue. Where is your `[...nextauth]` located exactly? So the whole path from your project's root folder.
kubasOP
./app/api/auth/[...nextauth]/route.ts
@kubas ./app/api/auth/[...nextauth]/route.ts
Ok, looks fine. Can you try putting the following into your
middleware.ts:export const config = {
matcher: [
'/((?!api/auth|login|register).*)',
],
}Or do you want to just protect specific routes or your app?