chore: reintroduce updated auth mechanism

This commit is contained in:
Andrew Bastin
2023-02-07 19:21:06 +05:30
parent cd72851289
commit ce0898956d
47 changed files with 1081 additions and 823 deletions

View File

@@ -122,16 +122,7 @@
<script lang="ts">
import { defineComponent } from "vue"
import {
signInUserWithGoogle,
signInUserWithGithub,
signInUserWithMicrosoft,
setProviderInfo,
currentUser$,
signInWithEmail,
linkWithFBCredentialFromAuthError,
getGithubCredentialFromResult,
} from "~/helpers/fb/auth"
import { platform } from "~/platform"
import IconGithub from "~icons/auth/github"
import IconGoogle from "~icons/auth/google"
import IconEmail from "~icons/auth/email"
@@ -174,6 +165,8 @@ export default defineComponent({
}
},
mounted() {
const currentUser$ = platform.auth.getCurrentUserStream()
this.subscribeToStream(currentUser$, (user) => {
if (user) this.hideModal()
})
@@ -186,8 +179,7 @@ export default defineComponent({
this.signingInWithGoogle = true
try {
await signInUserWithGoogle()
this.showLoginSuccess()
await platform.auth.signInUserWithGoogle()
} catch (e) {
console.error(e)
/*
@@ -202,35 +194,32 @@ export default defineComponent({
async signInWithGithub() {
this.signingInWithGitHub = true
try {
const result = await signInUserWithGithub()
const credential = getGithubCredentialFromResult(result)!
const token = credential.accessToken
setProviderInfo(result.providerId!, token!)
const result = await platform.auth.signInUserWithGithub()
this.showLoginSuccess()
} catch (e) {
console.error(e)
// This user's email is already present in Firebase but with other providers, namely Google or Microsoft
if (
(e as any).code === "auth/account-exists-with-different-credential"
) {
this.toast.info(`${this.t("auth.account_exists")}`, {
duration: 0,
closeOnSwipe: false,
action: {
text: `${this.t("action.yes")}`,
onClick: async (_, toastObject) => {
await linkWithFBCredentialFromAuthError(e)
this.showLoginSuccess()
if (!result) {
this.signingInWithGitHub = false
return
}
toastObject.goAway(0)
},
if (result.type === "success") {
// this.showLoginSuccess()
} else if (result.type === "account-exists-with-different-cred") {
this.toast.info(`${this.t("auth.account_exists")}`, {
duration: 0,
closeOnSwipe: false,
action: {
text: `${this.t("action.yes")}`,
onClick: async (_, toastObject) => {
await result.link()
this.showLoginSuccess()
toastObject.goAway(0)
},
})
} else {
this.toast.error(`${this.t("error.something_went_wrong")}`)
}
},
})
} else {
console.log("error logging into github", result.err)
this.toast.error(`${this.t("error.something_went_wrong")}`)
}
this.signingInWithGitHub = false
@@ -239,8 +228,8 @@ export default defineComponent({
this.signingInWithMicrosoft = true
try {
await signInUserWithMicrosoft()
this.showLoginSuccess()
await platform.auth.signInUserWithMicrosoft()
// this.showLoginSuccess()
} catch (e) {
console.error(e)
/*
@@ -259,11 +248,8 @@ export default defineComponent({
async signInWithEmail() {
this.signingInWithEmail = true
const actionCodeSettings = {
url: `${import.meta.env.VITE_BASE_URL}/enter`,
handleCodeInApp: true,
}
await signInWithEmail(this.form.email, actionCodeSettings)
await platform.auth
.signInWithEmail(this.form.email)
.then(() => {
this.mode = "email-sent"
setLocalConfig("emailForSignIn", this.form.email)

View File

@@ -22,7 +22,7 @@ import { ref } from "vue"
import IconLogOut from "~icons/lucide/log-out"
import { useToast } from "@composables/toast"
import { useI18n } from "@composables/i18n"
import { signOutUser } from "~/helpers/fb/auth"
import { platform } from "~/platform"
defineProps({
outline: {
@@ -47,7 +47,7 @@ const t = useI18n()
const logout = async () => {
try {
await signOutUser()
await platform.auth.signOutUser()
toast.success(`${t("auth.logged_out")}`)
} catch (e) {
console.error(e)