OAuth sign-in
An application wants users to authenticate through Discord.
Better Auth · Const
discord is Better Auth's provider identifier for Discord OAuth. Configure it under socialProviders with Discord credentials, then pass it as the provider value to signIn.social.
The discord constant is the provider identifier used in Better Auth's socialProviders configuration and in the client's signIn.social call. The server configuration supplies Discord credentials, while the client value selects Discord for the OAuth sign-in flow.
provider: "discord"| Name | Type | Description |
|---|---|---|
provider | string | The configured social provider identifier; use the literal value discord. |
A social sign-in operation that initiates Discord OAuth through the configured client.
socialProviders option.provider field to the literal identifier discord.permissions option.import { betterAuth } from "better-auth";
import { createAuthClient } from "better-auth/client";
export const auth = betterAuth({
socialProviders: {
discord: {
clientId: process.env.DISCORD_CLIENT_ID!,
clientSecret: process.env.DISCORD_CLIENT_SECRET!,
},
},
});
const authClient = createAuthClient();
await authClient.signIn.social({ provider: "discord" });Configure Discord on the server, then start the provider redirect from the client.
An application wants users to authenticate through Discord.
A server needs to register Discord alongside other social providers.
A Discord integration requests the OAuth bot scope.
discord used in a Better Auth integration?discord identifies Discord in both places: the server's socialProviders object and the client's signIn.social request. The client request uses { provider: "discord" } to select that configured provider.
Follow-up: How would you support Discord bot permissions? Add the provider's permissions option when using the bot scope, supplying either a bitwise combination or a specific permission value.
The server configuration requires clientId and clientSecret under socialProviders.discord. The client then calls authClient.signIn.social with the provider set to discord.
Follow-up: What must be changed after moving the auth routes? Update the Discord redirect URL to match the new auth route base path.
Discord OAuth requires a registered redirect URL. For local development, the documented callback is http://localhost:3000/api/auth/callback/discord; production should use the application's URL.
Follow-up: What if the application uses a custom auth route base path? Register the callback URL derived from that new base path instead of the default.
socialProviderssignIn.socialclientIdclientSecretpermissionscreateAuthClient