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

@@ -29,10 +29,7 @@ import IconCheck from "~icons/lucide/check"
import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import { useReadonlyStream } from "@composables/stream"
import { authIdToken$ } from "~/helpers/fb/auth"
const userAuthToken = useReadonlyStream(authIdToken$, null)
import { platform } from "~/platform"
const t = useI18n()
@@ -53,8 +50,9 @@ const copyIcon = refAutoReset<typeof IconCopy | typeof IconCheck>(
// Copy user auth token to clipboard
const copyUserAuthToken = () => {
if (userAuthToken.value) {
copyToClipboard(userAuthToken.value)
const token = platform.auth.getDevOptsBackendIDToken()
if (token) {
copyToClipboard(token)
copyIcon.value = IconCheck
toast.success(`${t("state.copied_to_clipboard")}`)
} else {

View File

@@ -219,7 +219,7 @@ import { showChat } from "@modules/crisp"
import { useSetting } from "@composables/settings"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import { TippyComponent } from "vue-tippy"
import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
import { invokeAction } from "@helpers/actions"
@@ -236,7 +236,10 @@ const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT")
const navigatorShare = !!navigator.share
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
watch(
() => ZEN_MODE.value,

View File

@@ -171,11 +171,10 @@ import IconUploadCloud from "~icons/lucide/upload-cloud"
import IconUserPlus from "~icons/lucide/user-plus"
import { breakpointsTailwind, useBreakpoints, useNetwork } from "@vueuse/core"
import { pwaDefferedPrompt, installPWA } from "@modules/pwa"
import { probableUser$ } from "@helpers/fb/auth"
import { platform } from "~/platform"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { invokeAction } from "@helpers/actions"
import { platform } from "~/index"
const t = useI18n()
@@ -194,7 +193,10 @@ const mdAndLarger = breakpoints.greater("md")
const network = reactive(useNetwork())
const currentUser = useReadonlyStream(probableUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getProbableUserStream(),
platform.auth.getProbableUser()
)
// Template refs
const tippyActions = ref<any | null>(null)

View File

@@ -172,7 +172,7 @@ import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { useToast } from "@composables/toast"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import { appendRESTCollections, restCollections$ } from "~/newstore/collections"
import { RESTCollectionImporters } from "~/helpers/import-export/import/importers"
import { StepReturnValue } from "~/helpers/import-export/steps"
@@ -263,7 +263,10 @@ watch(inputChooseGistToImportFrom, (url) => {
})
const myCollections = useReadonlyStream(restCollections$, [])
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
const importerAction = async (stepResults: StepReturnValue[]) => {
if (!importerModule.value) return

View File

@@ -99,7 +99,7 @@ import IconFolderPlus from "~icons/lucide/folder-plus"
import IconDownload from "~icons/lucide/download"
import IconGithub from "~icons/lucide/github"
import { computed, ref } from "vue"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { useToast } from "@composables/toast"
@@ -120,7 +120,10 @@ const emit = defineEmits<{
const toast = useToast()
const t = useI18n()
const collections = useReadonlyStream(graphqlCollections$, [])
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
// Template refs
const tippyActions = ref<any | null>(null)

View File

@@ -241,7 +241,7 @@ import {
} from "~/helpers/backend/helpers"
import { HoppRequestSaveContext } from "~/helpers/types/HoppRequestSaveContext"
import * as E from "fp-ts/Either"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import { createCollectionGists } from "~/helpers/gist"
import { invokeAction } from "~/helpers/actions"
@@ -318,7 +318,10 @@ const confirmModalTitle = ref<string | null>(null)
const filterTexts = ref("")
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
const myCollections = useReadonlyStream(restCollections$, [], "deep")
// Export - Import refs
@@ -1462,7 +1465,7 @@ const createCollectionGist = async () => {
(result) => {
toast.success(t("export.gist_created").toString())
creatingGistCollection.value = false
window.open(result.data.url)
window.open(result.data.html_url)
}
)
)()

View File

@@ -78,7 +78,7 @@
import { nextTick, ref, watch } from "vue"
import { GetMyTeamsQuery } from "~/helpers/backend/graphql"
import { onLoggedIn } from "@composables/auth"
import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
import { platform } from "~/platform"
import TeamListAdapter from "~/helpers/teams/TeamListAdapter"
import { useReadonlyStream } from "@composables/stream"
import { useLocalState } from "~/newstore/localstate"
@@ -111,7 +111,10 @@ const emit = defineEmits<{
(e: "update-selected-team", team: SelectedTeam): void
}>()
const currentUser = useReadonlyStream(currentUserInfo$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
const adapter = new TeamListAdapter(true)
const myTeams = useReadonlyStream(adapter.teamList$, null)
@@ -138,7 +141,9 @@ watch(
)
onLoggedIn(() => {
adapter.initialize()
try {
adapter.initialize()
} catch (e) {}
})
const onTeamSelectIntersect = () => {

View File

@@ -107,7 +107,7 @@ import IconDownload from "~icons/lucide/download"
import IconGithub from "~icons/lucide/github"
import { computed, ref } from "vue"
import { Environment } from "@hoppscotch/data"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import axios from "axios"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
@@ -141,7 +141,10 @@ const t = useI18n()
const loading = ref(false)
const myEnvironments = useReadonlyStream(environments$, [])
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
// Template refs
const tippyActions = ref<TippyComponent | null>(null)
@@ -187,7 +190,7 @@ const createEnvironmentGist = async () => {
)
toast.success(t("export.gist_created").toString())
window.open(res.html_url)
window.open(res.data.html_url)
} catch (e) {
toast.error(t("error.something_went_wrong").toString())
console.error(e)

View File

@@ -183,7 +183,7 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue"
import { isEqual } from "lodash-es"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import { Team } from "~/helpers/backend/graphql"
import { useReadonlyStream, useStream } from "@composables/stream"
import { useI18n } from "~/composables/i18n"
@@ -222,7 +222,10 @@ const globalEnvironment = computed(() => ({
variables: globalEnv.value,
}))
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
const updateSelectedTeam = (newSelectedTeam: SelectedTeam) => {
environmentType.value.selectedTeam = newSelectedTeam

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)

View File

@@ -82,7 +82,7 @@ import { ref, watchEffect, computed } from "vue"
import { pipe } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import { GQLError } from "~/helpers/backend/GQLClient"
import { currentUser$ } from "~/helpers/fb/auth"
import { platform } from "~/platform"
import { onAuthEvent, onLoggedIn } from "@composables/auth"
import { useReadonlyStream } from "@composables/stream"
@@ -102,7 +102,10 @@ usePageHead({
title: computed(() => t("navigation.profile")),
})
const currentUser = useReadonlyStream(currentUser$, null)
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
const displayName = ref(currentUser.value?.displayName)
watchEffect(() => (displayName.value = currentUser.value?.displayName))
@@ -121,7 +124,9 @@ const loading = computed(
)
onLoggedIn(() => {
adapter.initialize()
try {
adapter.initialize()
} catch (e) {}
})
onAuthEvent((ev) => {

View File

@@ -109,7 +109,7 @@ import { useI18n } from "~/composables/i18n"
import { useToast } from "~/composables/toast"
import { GetMyTeamsDocument, GetMyTeamsQuery } from "~/helpers/backend/graphql"
import { deleteUser } from "~/helpers/backend/mutations/Profile"
import { signOutUser } from "~/helpers/fb/auth"
import { platform } from "~/platform"
const t = useI18n()
const toast = useToast()
@@ -162,7 +162,7 @@ const deleteUserAccount = async () => {
deletingUser.value = false
showDeleteAccountModal.value = false
toast.success(t("settings.account_deleted"))
signOutUser()
platform.auth.signOutUser()
router.push(`/`)
}
)

View File

@@ -108,7 +108,9 @@ const loading = computed(
)
onLoggedIn(() => {
adapter.initialize()
try {
adapter.initialize()
} catch (e) {}
})
const displayModalAdd = (shouldDisplay: boolean) => {