Reddit social login
Users need to sign in with Reddit through an Auth.js application.
Auth.js · Const
Auth.js includes Reddit as a built-in OAuth provider. Configure Reddit credentials in NextAuth, and use duration: "permanent" when a refresh token is required.
The Reddit provider is a built-in OAuth integration. Add it to Auth.js with Reddit credentials; customize authorization parameters when you need a refresh token rather than the provider's default short-lived access token.
function default(config): OAuthConfig<Record<string, any>>| Name | Type | Description |
|---|---|---|
config | OAuthUserConfig<Record<string, any>> | Optional Reddit OAuth configuration, including client credentials and authorization overrides. |
OAuthConfig<Record<string, any>>
reddit.AUTH_REDDIT_ID and AUTH_REDDIT_SECRET as the provider environment variables.import NextAuth from "next-auth"
import Reddit from "next-auth/providers/reddit"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
Reddit({
clientId: process.env.REDDIT_CLIENT_ID,
clientSecret: process.env.REDDIT_CLIENT_SECRET,
authorization: { params: { duration: "permanent" } },
}),
],
})Configures Reddit sign-in and requests a permanent authorization so Auth.js can obtain a refresh token.
Users need to sign in with Reddit through an Auth.js application.
The application needs to renew Reddit access after the default token expires.
A project wants a standard Reddit OAuth integration without implementing provider endpoints itself.
The provider is imported from next-auth/providers/reddit and passed to NextAuth through the providers array. Credentials can be supplied explicitly with clientId and clientSecret, or the provider can use the documented environment-variable setup.
Follow-up: How would you obtain a refresh token? Set authorization.params.duration to "permanent" in the Reddit provider configuration.
The documented callback URL is /api/auth/callback/reddit under the application's origin. That URL must be registered in Reddit's application settings, and Reddit permits only one callback URL per client credential pair.
Follow-up: What deployment constraint follows from that limitation? A single Reddit credential pair cannot directly serve multiple callback URLs.
The default template requests only the identity scope and provides a one-hour access token. To request a refresh token, configure the authorization parameter duration as permanent.
Follow-up: Why is this configuration necessary for durable access? Without the permanent duration parameter, the documented default does not provide the refresh-token behavior needed for renewal.
OAuthConfigOAuthUserConfigNextAuthauthorizationdurationAUTH_REDDIT_IDAUTH_REDDIT_SECRET