Discord
WIPSign in with Discord, keyed on the account's snowflake id
- Create an application in the Discord Developer Portal.
- Under OAuth2, add
https://app.example.com/auth/providers/oauth:discord/callbackas a redirect. - Copy the client id and secret.
import { discord } from '@gentleduck/auth/providers/oauth/discord'
discord({
clientId: process.env.DISCORD_CLIENT_ID ?? '',
clientSecret: process.env.DISCORD_CLIENT_SECRET ?? '',
redirectUri: 'https://app.example.com/auth/providers/oauth:discord/callback',
stateSigningSecret: process.env.OAUTH_STATE_SECRET ?? '',
nonceStore,
profileToIdentityProfile: (p) => (p.email ? { email: p.email, username: `discord:${p.sub}`, name: p.name } : null),
})
The provider id is oauth:discord, and the default scopes are identify email.
subis the account's id, which survives a username change.nameis the display name, else the username.avatarUrlis built from the avatar hash on Discord's CDN.emailVerifiedis set only when Discord answersverified: true.
The routes, the options every provider shares and account linking are on the OAuth page.