Domain-based access control
Permit only accounts from an approved email domain.
Auth.js · Function
The signIn callback decides whether an authentication attempt may continue. Return true to allow it, false to deny it, or a URL string to redirect the user.
The callback runs during the sign-in flow and decides whether access continues. Return true to proceed, false to stop and send the user to the error page, or a URL string to redirect the user there; asynchronous work such as checking a database or external API is supported.
signIn: (params) => Awaitable<string | boolean>| Name | Type | Description |
|---|---|---|
params | object | Object containing callback context; the documented example destructures profile from it. |
Awaitable<string | boolean>
import NextAuth from "next-auth"
export const { handlers, auth } = NextAuth({
providers: [],
callbacks: {
async signIn({ profile }) {
return profile?.email?.endsWith("@example.com") ?? false
},
},
})Allows sign-in only when the profile email ends with the approved domain.
Permit only accounts from an approved email domain.
Consult an external service before allowing authentication.
Send an authenticated user to a custom destination.
The callback returns an Awaitable<string | boolean>. A boolean controls whether sign-in proceeds, while a string supplies a redirect destination.
Follow-up: What happens when it returns false? The sign-in flow stops and the user is redirected to the error page.
Return true to continue, false to deny access, or a string to redirect the user to a specified URL. Because callbacks are asynchronous, the function may perform asynchronous checks before returning.
Follow-up: How could access be restricted without a local database? Await an external API or database check and return its authorization result.
It receives a params object, which can be destructured for values such as profile. The documented example checks the profile email domain and returns the resulting boolean.
Follow-up: What should an implementation do for providers without the expected profile field? Use optional access or provider-specific checks so the callback returns an explicit decision.
callbacksjwt callbacksession callbackredirect callbackAccessDenied