From b4976c1ddc94751416e8c670055a9ecaef41fcf9 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 22 Sep 2025 19:04:08 -0700 Subject: [PATCH] Revert: Move VueFire persistence configuration to initialization (#5614) (#5729) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This reverts PR #5614 which moved VueFire persistence configuration to initialization. ## Reason for Revert It breaks Google SSO login with error: ``` useErrorHandling.ts:12 FirebaseError: Firebase: Error (auth/argument-error). at createErrorInternal (index-c92d61ad.js:506:41) at _assert (index-c92d61ad.js:512:15) at _withDefaultResolver (index-c92d61ad.js:9237:5) at signInWithPopup (index-c92d61ad.js:9457:30) at executeAuthAction.createCustomer (firebaseAuthStore.ts:263:25) at executeAuthAction (firebaseAuthStore.ts:223:28) at Proxy.loginWithGoogle (firebaseAuthStore.ts:262:5) at Proxy.wrappedAction (pinia.mjs:1405:26) at useFirebaseAuthActions.ts:104:28 at Object.signInWithGoogle (useErrorHandling.ts:39:22) ``` ## Changes - Reverts commit ea4e57b60 "Move VueFire persistence configuration to initialization (#5614)" - Restores previous Firebase auth persistence behavior ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5729-Revert-Move-VueFire-persistence-configuration-to-initialization-5614-2776d73d3650814c9b80d9c67c852874) by [Unito](https://www.unito.io) --- src/main.ts | 21 ++----------------- src/stores/firebaseAuthStore.ts | 4 ++++ .../tests/store/firebaseAuthStore.test.ts | 7 +++++++ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main.ts b/src/main.ts index 267de4f44..b15d4067f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,11 +2,6 @@ import { definePreset } from '@primevue/themes' import Aura from '@primevue/themes/aura' import * as Sentry from '@sentry/vue' import { initializeApp } from 'firebase/app' -import { - browserLocalPersistence, - browserSessionPersistence, - indexedDBLocalPersistence -} from 'firebase/auth' import { createPinia } from 'pinia' import 'primeicons/primeicons.css' import PrimeVue from 'primevue/config' @@ -14,7 +9,7 @@ import ConfirmationService from 'primevue/confirmationservice' import ToastService from 'primevue/toastservice' import Tooltip from 'primevue/tooltip' import { createApp } from 'vue' -import { VueFire, VueFireAuthWithDependencies } from 'vuefire' +import { VueFire, VueFireAuth } from 'vuefire' import { FIREBASE_CONFIG } from '@/config/firebase' import '@/lib/litegraph/public/css/litegraph.css' @@ -71,18 +66,6 @@ app .use(i18n) .use(VueFire, { firebaseApp, - modules: [ - // Configure Firebase Auth persistence: localStorage first, IndexedDB last. - // Localstorage is preferred to IndexedDB for mobile Safari compatibility. - VueFireAuthWithDependencies({ - dependencies: { - persistence: [ - browserLocalPersistence, - browserSessionPersistence, - indexedDBLocalPersistence - ] - } - }) - ] + modules: [VueFireAuth()] }) .mount('#vue-app') diff --git a/src/stores/firebaseAuthStore.ts b/src/stores/firebaseAuthStore.ts index 6e4974839..698efff3e 100644 --- a/src/stores/firebaseAuthStore.ts +++ b/src/stores/firebaseAuthStore.ts @@ -6,10 +6,12 @@ import { GoogleAuthProvider, type User, type UserCredential, + browserLocalPersistence, createUserWithEmailAndPassword, deleteUser, onAuthStateChanged, sendPasswordResetEmail, + setPersistence, signInWithEmailAndPassword, signInWithPopup, signOut, @@ -80,6 +82,8 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => { // Retrieves the Firebase Auth instance. Returns `null` on the server. // When using this function on the client in TypeScript, you can force the type with `useFirebaseAuth()!`. const auth = useFirebaseAuth()! + // Set persistence to localStorage (works in both browser and Electron) + void setPersistence(auth, browserLocalPersistence) onAuthStateChanged(auth, (user) => { currentUser.value = user diff --git a/tests-ui/tests/store/firebaseAuthStore.test.ts b/tests-ui/tests/store/firebaseAuthStore.test.ts index ef8ffe0bd..d37c3857a 100644 --- a/tests-ui/tests/store/firebaseAuthStore.test.ts +++ b/tests-ui/tests/store/firebaseAuthStore.test.ts @@ -150,6 +150,13 @@ describe('useFirebaseAuthStore', () => { expect(store.loading).toBe(false) }) + it('should set persistence to local storage on initialization', () => { + expect(firebaseAuth.setPersistence).toHaveBeenCalledWith( + mockAuth, + firebaseAuth.browserLocalPersistence + ) + }) + it('should properly clean up error state between operations', async () => { // First, cause an error const mockError = new Error('Invalid password')