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 || "",
},
},
account: {
accountLinking: {
trustedProviders: ["google", "github"],
requireEmailVerified: true,
},
},
});

View File

@@ -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,