Discord sign-in
Users authenticate through their Discord accounts in an Auth.js application.
Auth.js · Const
Discord is a built-in Auth.js OAuth provider. Call it with a Discord client ID and secret, then include the returned configuration in Auth.js’s providers list.
Calling Discord with OAuth client credentials produces a provider configuration that Auth.js can include in its providers list. Auth.js supplies Discord’s standard OAuth settings automatically, while the callback endpoint must be registered as https://example.com/api/auth/callback/discord.
Discord<P extends DiscordProfile>(options: OAuthUserConfig<P>): OAuthConfig<P>| Name | Type | Description |
|---|---|---|
options | OAuthUserConfig<P> | OAuth configuration for the Discord provider, including the client credentials; generic profile type P extends DiscordProfile. |
OAuthConfig<P>
import { Auth } from "@auth/core"
import Discord from "@auth/core/providers/discord"
const response = await Auth(new Request(origin), {
providers: [
Discord({
clientId: process.env.DISCORD_CLIENT_ID!,
clientSecret: process.env.DISCORD_CLIENT_SECRET!,
}),
],
})Creates an Auth.js request handler configured with Discord OAuth credentials.
Users authenticate through their Discord accounts in an Auth.js application.
An application needs a standard OAuth setup without manually specifying Discord endpoints.
A project needs Discord profile data represented with a typed profile shape.
The Discord factory accepts OAuth user configuration and returns an OAuth provider configuration. Add its result to the Auth.js providers array with the Discord client ID and client secret.
Follow-up: What callback URL should be registered? Use https://example.com/api/auth/callback/discord, matching the provider identifier.
The provider has built-in defaults, so the normal setup only supplies clientId and clientSecret. Auth.js then uses the resulting configuration during the OAuth flow.
Follow-up: How would you change a built-in default? Follow Auth.js’s customization approach for overriding a built-in OAuth provider.
The provider function is generic over a profile type extending DiscordProfile. It accepts OAuthUserConfig<P> and returns OAuthConfig<P>, allowing the provider configuration to preserve the profile type.
Follow-up: What does DiscordProfile represent? It corresponds to Discord’s documented user structure and also permits additional string-keyed values.
DiscordProfileOAuthUserConfigOAuthConfigAuthcustomizing a built-in OAuth provider