Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure NextAuth to allow account linking between different providers in development environment #248

Merged
merged 5 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
GITHUB_OAUTH_PROVIDER_ENABLED = "true"
GITHUB_OAUTH_PROVIDER_ENABLED = "true"
DANGEROUS_ACCOUNT_LINKING_ENABLED = "true"
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
GITHUB_OAUTH_PROVIDER_ENABLED = "false"
DANGEROUS_ACCOUNT_LINKING_ENABLED = "false"
18 changes: 16 additions & 2 deletions pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const authOptions = {
Auth0Provider({
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
issuer: process.env.AUTH0_ISSUER
issuer: process.env.AUTH0_ISSUER,
// Enable dangerous account linking in dev environment
...(process.env.DANGEROUS_ACCOUNT_LINKING_ENABLED == 'true'
? { allowDangerousEmailAccountLinking: true }
: {})
})
// ...add more providers here
],
Expand All @@ -32,9 +36,19 @@ if (process.env.GITHUB_OAUTH_PROVIDER_ENABLED == 'true') {
authOptions.providers.push(
GithubProvider({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET
clientSecret: process.env.GITHUB_SECRET,
// Enable dangerous account linking in dev environment
...(process.env.DANGEROUS_ACCOUNT_LINKING_ENABLED == 'true'
? { allowDangerousEmailAccountLinking: true }
: {})
})
);
}

export default NextAuth(authOptions);

/* Test Cases
Auth0 Google/GitHub -> GitHub
GitHub -> Auth0 Google/GitHub

Tested on Incognito tab of Microsoft Edge, Brave, Safari, Chrome, FireFox*/