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 || "",
|
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")
|
? 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,
|
||||||
|
|||||||
Reference in New Issue
Block a user