fix: oauth callback linking on trusted provider

This commit is contained in:
Bereket Engida
2024-09-28 08:21:38 +03:00
parent ee3255816a
commit eb3952a135
2 changed files with 2 additions and 10 deletions

View File

@@ -86,10 +86,4 @@ export const auth = betterAuth({
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "", clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
}, },
}, },
account: {
accountLinking: {
trustedProviders: ["google", "github"],
requireEmailVerified: true,
},
},
}); });

View File

@@ -99,9 +99,7 @@ export const callbackOAuth = createAuthEndpoint(
? trustedProviders.includes(provider.id as "apple") ? trustedProviders.includes(provider.id as "apple")
: true; : true;
const shouldLink = if (!hasBeenLinked && (!user.emailVerified || !isTrustedProvider)) {
!hasBeenLinked && user.emailVerified && isTrustedProvider;
if (!shouldLink) {
let url: URL; let url: URL;
try { try {
url = new URL(currentURL || callbackURL); url = new URL(currentURL || callbackURL);
@@ -114,7 +112,7 @@ export const callbackOAuth = createAuthEndpoint(
throw c.redirect(url.toString()); throw c.redirect(url.toString());
} }
if (shouldLink) { if (!hasBeenLinked) {
try { try {
await c.context.internalAdapter.linkAccount({ await c.context.internalAdapter.linkAccount({
providerId: provider.id, providerId: provider.id,