hari5h
hari5h4mo ago

Discord OAuth reauthorization

Hey all, I've successfully set up convex-auth in my project and in the process of hooking up the OAuth providers. GitHub seems to be working fine, however, Discord is making me reauthorize myself everytime I log out. According to the Discord docs, we need to pass in prompt=none to the Authorization URL (https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-authorization-url-example) Is there any way to do this currently with useAuthActions() and the signIn() function? I've tried onClick={() => signIn("discord", { prompt: "none" })} as suggested in the Auth.js GitHub (https://github.com/nextauthjs/next-auth/discussions/3490) But it doesn't work as it seems only redirectTo is a param we can pass. Any ideas?
GitHub
Discord is always asking to reauthorize the application · nextauthj...
Hello, Before opening a potential issue, I'd like to ask a question. I set up Discord with Next-Auth V4 but I encounter a problem I didn't have with V3. When clicking on "signin with d...
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
3 Replies
Convex Bot
Convex Bot4mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
sshader
sshader4mo ago
Convex Auth doesn't currently support additional params to customize the authorization URL. I'd potentially try defining a custom DiscordProvider that always had prompt=none in the authorization URL. High level code is something like
import Discord from @auth/core/providers/discord

export function MyCustomDiscordProvider(options) {
const discordProvider = Discord(options)
const originalAuthorizationUrl = discordProvider.authorization;
const authorizationUrlWithPromptNone = // modify URL
return {
...discordProvider,
authorization: authorizationUrlWithPromptNone
}
}
import Discord from @auth/core/providers/discord

export function MyCustomDiscordProvider(options) {
const discordProvider = Discord(options)
const originalAuthorizationUrl = discordProvider.authorization;
const authorizationUrlWithPromptNone = // modify URL
return {
...discordProvider,
authorization: authorizationUrlWithPromptNone
}
}
hari5h
hari5hOP4mo ago
That's a good idea, thanks! Had a play around a figured it out if anyone else is stuck. Found a way to do it by passing in a custom authorization value when setting up the provider
import { convexAuth } from "@convex-dev/auth/server";
import Discord from "@auth/core/providers/discord";
import GitHub from "@auth/core/providers/github";

const DISCORD_AUTHORIZATION_URL =
"https://discord.com/api/oauth2/authorize?scope=identify+email&prompt=none";

export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Discord({
authorization: DISCORD_AUTHORIZATION_URL,
}),
GitHub,
],
});
import { convexAuth } from "@convex-dev/auth/server";
import Discord from "@auth/core/providers/discord";
import GitHub from "@auth/core/providers/github";

const DISCORD_AUTHORIZATION_URL =
"https://discord.com/api/oauth2/authorize?scope=identify+email&prompt=none";

export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Discord({
authorization: DISCORD_AUTHORIZATION_URL,
}),
GitHub,
],
});

Did you find this page helpful?