All snippets
TypeScript

Fix NextAuth Discord login: issuer must be configured

Discord now sends iss on the OAuth callback, and NextAuth v4 rejects it unless the provider declares an issuer.

NextAuthDiscordOAuth

Discord started adding an iss parameter to its OAuth callback (RFC 9207). NextAuth v4 hands the callback to openid-client, which checks iss against the provider's issuer. The built-in Discord provider doesn't set one, so every login fails with OAUTH_CALLBACK_ERROR: issuer must be configured on the issuer, and the sign-in page shows "Try signing in with a different account".

The fix is one line on the provider:

ts
import NextAuth, { type NextAuthOptions } from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

export const authOptions: NextAuthOptions = {
  providers: [
    DiscordProvider({
      clientId: process.env.DISCORD_CLIENT_ID!,
      clientSecret: process.env.DISCORD_CLIENT_SECRET!,
      // Discord sends `iss` on the callback; openid-client rejects it
      // unless the provider declares a matching issuer.
      issuer: "https://discord.com",
    }),
  ],
};

export default NextAuth(authOptions);

The provider already lists its endpoints, so NextAuth uses issuer as-is and doesn't make a discovery request.

From the projectPortfolio