mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
fix: oauth callback linking on trusted provider
This commit is contained in:
@@ -86,10 +86,4 @@ export const auth = betterAuth({
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
|
||||
},
|
||||
},
|
||||
account: {
|
||||
accountLinking: {
|
||||
trustedProviders: ["google", "github"],
|
||||
requireEmailVerified: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -99,9 +99,7 @@ export const callbackOAuth = createAuthEndpoint(
|
||||
? trustedProviders.includes(provider.id as "apple")
|
||||
: true;
|
||||
|
||||
const shouldLink =
|
||||
!hasBeenLinked && user.emailVerified && isTrustedProvider;
|
||||
if (!shouldLink) {
|
||||
if (!hasBeenLinked && (!user.emailVerified || !isTrustedProvider)) {
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(currentURL || callbackURL);
|
||||
@@ -114,7 +112,7 @@ export const callbackOAuth = createAuthEndpoint(
|
||||
throw c.redirect(url.toString());
|
||||
}
|
||||
|
||||
if (shouldLink) {
|
||||
if (!hasBeenLinked) {
|
||||
try {
|
||||
await c.context.internalAdapter.linkAccount({
|
||||
providerId: provider.id,
|
||||
|
||||
Reference in New Issue
Block a user