Skip to content
Migrating from NextAuth.js v4? Read our migration guide.
Custom Signin

Custom Sign-in Page

To add a custom sign-in page, you’ll need to define the path to your page in the pages object in your Auth.js configuration. Make sure a route / page actually exists at the path you’re defining here!

In additionally, we’ll have to export a map of and to easily consume in our custom page if we want to dynamically render the correct buttons, based on what we’ve defined in our auth.ts configuration. Because you can pass your providers to the providers array as both a function, or the result of calling that function, this example providerMap handles both cases.

import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"
import Credentials from "next-auth/providers/credentials"
import type { Provider } from "next-auth/providers"
const providers: Provider[] = [
    credentials: { password: { label: "Password", type: "password" } },
    authorize(c) {
      if (c.password !== "password") return null
      return {
        id: "test",
        name: "Test User",
        email: "",
export const providerMap = => {
  if (typeof provider === "function") {
    const providerData = provider()
    return { id:, name: }
  } else {
    return { id:, name: }
export const { handlers, auth, signIn, signOut } = NextAuth({
  pages: {
    signIn: "/signin",

We can now build our own custom sign in page.

import { redirect } from "next/navigation"
import { signIn, auth, providerMap } from "@/auth.ts"
import { AuthError } from "next-auth"
export default async function SignInPage() {
  return (
    <div className="flex flex-col gap-2">
      {Object.values(providerMap).map((provider) => (
          action={async () => {
            "use server"
            try {
              await signIn(
            } catch (error) {
              // Signin can fail for a number of reasons, such as the user
              // not existing, or the user not having the correct role.
              // In some cases, you may want to redirect to a custom error
              if (error instanceof AuthError) {
                return redirect(`${SIGNIN_ERROR_URL}?error=${error.type}`)
              // Otherwise if a redirects happens NextJS can handle it
              // so you can just re-thrown the error and let NextJS handle it.
              // Docs:
              throw error
          <button type="submit">
            <span>Sign in with {}</span>

Then when calling signIn without any arguments anywhere in your application, the custom signin page will appear.

Custom Sign-in Page
Auth.js © Balázs Orbán and Team - 2024