Standard Cognito login
Add Cognito sign-in to an Auth.js application using the provider's default configuration and environment variables.
Auth.js · Const
Cognito is a built-in Auth.js OpenID Connect provider. Register it directly or configure it with a client ID, client secret, and Cognito issuer.
Cognito is a built-in OpenID Connect provider. Add it to Auth.js configuration directly, or call it with client credentials and an issuer when explicit configuration is needed; the issuer identifies the Cognito user pool.
Cognito(options)| Name | Type | Description |
|---|---|---|
options | OAuthUserConfig<P> | Provider options including OAuth client settings; the reference types this as OAuthUserConfig<P>. |
OAuthConfig<P>
import NextAuth from "next-auth"
import Cognito from "next-auth/providers/cognito"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Cognito],
})Register the built-in Cognito provider with NextAuth; credentials and issuer are read from the documented environment variables.
Add Cognito sign-in to an Auth.js application using the provider's default configuration and environment variables.
Supply explicit Cognito credentials and the user-pool issuer when defaults are insufficient.
Connect Auth.js to a Cognito hosted UI through the required OAuth callback route.
Cognito is registered as a built-in provider in the Auth.js providers array. The shorthand form uses the imported provider directly, while the configured form calls Cognito with clientId, clientSecret, and issuer.
Follow-up: Why is issuer needed? It identifies the Cognito OpenID Connect issuer and lets Auth.js use the provider's discovery configuration.
The callback URL for a typical Next.js deployment is https://example.com/api/auth/callback/cognito. Cognito must be configured to allow the corresponding callback URL.
Follow-up: What should be checked if sign-in fails after callback configuration? Verify the hosted domain and the Cognito app-client settings.
Auth.js treats Cognito as an OpenID Connect provider by default and supplies a default provider configuration. Override it by passing an options object to the provider function.
Follow-up: What is the resulting type of the provider factory? The reference gives OAuthConfig<P>, where P extends CognitoProfile.
CognitoProfileOAuthUserConfigOAuthConfigprovidersissuer