Clerk + Discord OAuth is a great fit for this use case. When users sign up/sign in via Discord, Clerk automatically creates (or links) a SaaS user account for them. This is standard social login behavior in Clerk—no extra "upon joining" logic needed for basic auth.
1. Enable Discord in Clerk (Quick Setup)
Development Instance (easiest for testing)
- Go to your Clerk Dashboard → SSO connections.
- Click Add connection → For all users → Select Discord.
- Enable it (Clerk uses shared credentials—no extra config needed).
Production Instance
-
In Clerk Dashboard → SSO connections → Add Discord connection.
-
Toggle on Enable for sign-up and sign-in and Use custom credentials.
-
Copy the Redirect URI shown (e.g., https://your-domain.accounts.dev/sign-in or similar for production).
-
Create Discord OAuth App:
- Go to Discord Developer Portal.
- New Application → Go to OAuth2 tab.
- Add the Redirect URI from Clerk under Redirects.
- Copy Client ID and Client Secret (reset secret if needed).
-
Paste Client ID + Secret back into Clerk and save.
Test via your app's Account Portal (sign-in page) or <SignIn /> component.
2. Frontend Integration (Next.js / React example)
Assuming you already have Clerk set up:
import { SignIn } from "@clerk/nextjs";
export default function Page() {
return <SignIn path="/sign-in" routing="path" signUpUrl="/sign-up" />;
}
Discord button appears automatically once enabled. Users signing in with Discord become SaaS users in Clerk (with externalAccounts linked to their Discord profile).
Clerk handles:
- Sign-up / sign-in equivalence (new users auto-created).
- User metadata (name, email, avatar from Discord).
- Session management, JWTs, etc.
3. Backend / User Management
- Use Clerk's Backend API or SDK to fetch user details:
clerkClient.users.getUser(userId).
- Access Discord-linked data via
user.externalAccounts.
- Webhooks (recommended for SaaS): Listen to
user.created, user.updated to sync to your database (e.g., create a profile, assign default role, send welcome email).
4. Advanced: Discord Guild/Member Features
If you want to:
- Check if the user is in your Discord server (guild).
- Sync roles, grant access on join, or manage members.
After auth:
- Get the OAuth access token from Clerk:
const { getToken } = useAuth(); then request Discord token with appropriate scopes.
- Use Discord API endpoints (
/users/@me/guilds, etc.) with the token.
Scopes (add in Clerk when using custom credentials):
- Default:
identify email
- Extra for guilds:
guilds (list servers), guilds.members.read (member details).
Example flow from community projects: After Clerk sign-in, use server actions to call Discord API for role management.
Bot Integration Tip: For automatic role assignment on server join, combine this with a Discord bot that listens for member joins and checks against your Clerk user database (via Discord ID).
Common Gotchas
- Redirect URI mismatches → Exact match required (including protocol, no trailing slashes issues). Use Clerk's provided one.
- Production vs Dev: Always use custom credentials in prod.
- Rate limits / permissions: Be careful with Discord API calls.
- Existing users: Allow linking Discord in user profile if they signed up another way.
Next Steps / Resources
- Official: Clerk Discord Guide.
- Clerk + Next.js social connections overview.
- For full Discord member/role management examples, check tutorials using Clerk + Discord API (e.g., Brian Morrison's projects).
If you share more details (tech stack like Next.js, what "upon joining" specifically means—e.g., auto-role, server invite, paid gating), I can give more targeted code/webhook examples or help debug!
Clerk + Discord OAuth is a great fit for this use case. When users sign up/sign in via Discord, Clerk automatically creates (or links) a SaaS user account for them. This is standard social login behavior in Clerk—no extra "upon joining" logic needed for basic auth.
1. Enable Discord in Clerk (Quick Setup)
Development Instance (easiest for testing)
Production Instance
In Clerk Dashboard → SSO connections → Add Discord connection.
Toggle on Enable for sign-up and sign-in and Use custom credentials.
Copy the Redirect URI shown (e.g.,
https://your-domain.accounts.dev/sign-inor similar for production).Create Discord OAuth App:
Paste Client ID + Secret back into Clerk and save.
Test via your app's Account Portal (sign-in page) or
<SignIn />component.2. Frontend Integration (Next.js / React example)
Assuming you already have Clerk set up:
Discord button appears automatically once enabled. Users signing in with Discord become SaaS users in Clerk (with
externalAccountslinked to their Discord profile).Clerk handles:
3. Backend / User Management
clerkClient.users.getUser(userId).user.externalAccounts.user.created,user.updatedto sync to your database (e.g., create a profile, assign default role, send welcome email).4. Advanced: Discord Guild/Member Features
If you want to:
After auth:
const { getToken } = useAuth();then request Discord token with appropriate scopes./users/@me/guilds, etc.) with the token.Scopes (add in Clerk when using custom credentials):
identify emailguilds(list servers),guilds.members.read(member details).Example flow from community projects: After Clerk sign-in, use server actions to call Discord API for role management.
Bot Integration Tip: For automatic role assignment on server join, combine this with a Discord bot that listens for member joins and checks against your Clerk user database (via Discord ID).
Common Gotchas
Next Steps / Resources
If you share more details (tech stack like Next.js, what "upon joining" specifically means—e.g., auto-role, server invite, paid gating), I can give more targeted code/webhook examples or help debug!