How to properly setup a custom login page in NextAuth
Answered
The Fog from Human Resources posted this in #help-forum
So I have a login page designed and i want to use Next-Auth to handle my sessions, now i want my login page to be /login so the NextAuth signin function should point to that, but instead it points to /login/signin
Here is my src/auth/index.ts file
Here is my src/auth/index.ts file
import NextAuth, { NextAuthConfig, User } from "next-auth";
import Credentials from "next-auth/providers/credentials";
const BASE_PATH = "/login";
const authOptions: NextAuthConfig = {
providers: [
Credentials({
name: "Credentials",
credentials: {
username: {
label: "Username",
type: "text",
placeholder: "Enter Name...",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials): Promise<User | null> {
return null; // TODO
},
}),
],
basePath: BASE_PATH,
secret: process.env.NEXTAUTH_JWT_SECRET,
pages: {
signIn: BASE_PATH,
},
};
export const { handlers, auth, signIn, signOut } = NextAuth(authOptions);Answered by The Fog from Human Resources
Remove
basePath or else it wont work, only keep the signIn in pages1 Reply
Remove
basePath or else it wont work, only keep the signIn in pagesAnswer