fix: link github and google (#2626)
This commit is contained in:
@@ -128,6 +128,7 @@ import {
|
|||||||
currentUser$,
|
currentUser$,
|
||||||
signInWithEmail,
|
signInWithEmail,
|
||||||
linkWithFBCredential,
|
linkWithFBCredential,
|
||||||
|
linkWithFBCredentialFromAuthError,
|
||||||
getGithubCredentialFromResult,
|
getGithubCredentialFromResult,
|
||||||
} from "~/helpers/fb/auth"
|
} from "~/helpers/fb/auth"
|
||||||
import { setLocalConfig } from "~/newstore/localpersistence"
|
import { setLocalConfig } from "~/newstore/localpersistence"
|
||||||
@@ -218,8 +219,6 @@ export default defineComponent({
|
|||||||
if (e.code === "auth/account-exists-with-different-credential") {
|
if (e.code === "auth/account-exists-with-different-credential") {
|
||||||
// Step 2.
|
// Step 2.
|
||||||
// User's email already exists.
|
// User's email already exists.
|
||||||
// The pending Google credential.
|
|
||||||
const pendingCred = e.credential
|
|
||||||
this.$toast.info(`${this.$t("auth.account_exists")}`, {
|
this.$toast.info(`${this.$t("auth.account_exists")}`, {
|
||||||
duration: 0,
|
duration: 0,
|
||||||
closeOnSwipe: false,
|
closeOnSwipe: false,
|
||||||
@@ -227,7 +226,7 @@ export default defineComponent({
|
|||||||
text: `${this.$t("action.yes")}`,
|
text: `${this.$t("action.yes")}`,
|
||||||
onClick: async (_, toastObject) => {
|
onClick: async (_, toastObject) => {
|
||||||
const { user } = await signInUserWithGoogle()
|
const { user } = await signInUserWithGoogle()
|
||||||
await linkWithFBCredential(user, pendingCred)
|
await linkWithFBCredentialFromAuthError(user, e)
|
||||||
|
|
||||||
this.showLoginSuccess()
|
this.showLoginSuccess()
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
signOut,
|
signOut,
|
||||||
linkWithCredential,
|
linkWithCredential,
|
||||||
AuthCredential,
|
AuthCredential,
|
||||||
|
AuthError,
|
||||||
UserCredential,
|
UserCredential,
|
||||||
updateProfile,
|
updateProfile,
|
||||||
updateEmail,
|
updateEmail,
|
||||||
@@ -239,6 +240,24 @@ export async function linkWithFBCredential(
|
|||||||
return await linkWithCredential(user, credential)
|
return await linkWithCredential(user, credential)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Links account with another account given in a auth/account-exists-with-different-credential error
|
||||||
|
*
|
||||||
|
* @param user - User who has the errors
|
||||||
|
*
|
||||||
|
* @param error - Error caught after trying to login
|
||||||
|
*
|
||||||
|
* @returns Promise of UserCredential
|
||||||
|
*/
|
||||||
|
export async function linkWithFBCredentialFromAuthError(
|
||||||
|
user: User,
|
||||||
|
error: unknown
|
||||||
|
) {
|
||||||
|
// Marked as not null since this function is supposed to be called after an auth/account-exists-with-different-credential error, ie credentials actually exist
|
||||||
|
const credentials = OAuthProvider.credentialFromError(error as AuthError)!
|
||||||
|
return await linkWithCredential(user, credentials)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an email with the signin link to the user
|
* Sends an email with the signin link to the user
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user