Skip to content

Commit ea4e57b

Browse files
Move VueFire persistence configuration to initialization (#5614)
Currently, we set persistence method in the auth store setup. This creates pattern of using the default on init (indexed DB) up until the firebase store is initialized and `setPersistence` is called. For devices that don't support indexed DB or have the connection aggresively terminated or cleared, like [Safari](https://comfy-org.sentry.io/issues/6879071102/?project=4509681221369857&query=is%3Aunresolved&referrer=issue-stream), this can create problems with maintaing auth persistence. Fix by setting persistence method in the initialization in main.ts ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5614-Move-VueFire-persistence-configuration-to-initialization-2716d73d3650817480e0c8feb1f37b9a) by [Unito](https://www.unito.io) --------- Co-authored-by: Claude <[email protected]>
1 parent 4789d86 commit ea4e57b

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/main.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import { definePreset } from '@primevue/themes'
22
import Aura from '@primevue/themes/aura'
33
import * as Sentry from '@sentry/vue'
44
import { initializeApp } from 'firebase/app'
5+
import {
6+
browserLocalPersistence,
7+
browserSessionPersistence,
8+
indexedDBLocalPersistence
9+
} from 'firebase/auth'
510
import { createPinia } from 'pinia'
611
import 'primeicons/primeicons.css'
712
import PrimeVue from 'primevue/config'
813
import ConfirmationService from 'primevue/confirmationservice'
914
import ToastService from 'primevue/toastservice'
1015
import Tooltip from 'primevue/tooltip'
1116
import { createApp } from 'vue'
12-
import { VueFire, VueFireAuth } from 'vuefire'
17+
import { VueFire, VueFireAuthWithDependencies } from 'vuefire'
1318

1419
import { FIREBASE_CONFIG } from '@/config/firebase'
1520
import '@/lib/litegraph/public/css/litegraph.css'
@@ -66,6 +71,18 @@ app
6671
.use(i18n)
6772
.use(VueFire, {
6873
firebaseApp,
69-
modules: [VueFireAuth()]
74+
modules: [
75+
// Configure Firebase Auth persistence: localStorage first, IndexedDB last.
76+
// Localstorage is preferred to IndexedDB for mobile Safari compatibility.
77+
VueFireAuthWithDependencies({
78+
dependencies: {
79+
persistence: [
80+
browserLocalPersistence,
81+
browserSessionPersistence,
82+
indexedDBLocalPersistence
83+
]
84+
}
85+
})
86+
]
7087
})
7188
.mount('#vue-app')

src/stores/firebaseAuthStore.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import {
66
GoogleAuthProvider,
77
type User,
88
type UserCredential,
9-
browserLocalPersistence,
109
createUserWithEmailAndPassword,
1110
deleteUser,
1211
onAuthStateChanged,
1312
sendPasswordResetEmail,
14-
setPersistence,
1513
signInWithEmailAndPassword,
1614
signInWithPopup,
1715
signOut,
@@ -80,8 +78,6 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
8078
// Retrieves the Firebase Auth instance. Returns `null` on the server.
8179
// When using this function on the client in TypeScript, you can force the type with `useFirebaseAuth()!`.
8280
const auth = useFirebaseAuth()!
83-
// Set persistence to localStorage (works in both browser and Electron)
84-
void setPersistence(auth, browserLocalPersistence)
8581

8682
onAuthStateChanged(auth, (user) => {
8783
currentUser.value = user

tests-ui/tests/store/firebaseAuthStore.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@ describe('useFirebaseAuthStore', () => {
148148
expect(store.loading).toBe(false)
149149
})
150150

151-
it('should set persistence to local storage on initialization', () => {
152-
expect(firebaseAuth.setPersistence).toHaveBeenCalledWith(
153-
mockAuth,
154-
firebaseAuth.browserLocalPersistence
155-
)
156-
})
157-
158151
it('should properly clean up error state between operations', async () => {
159152
// First, cause an error
160153
const mockError = new Error('Invalid password')

0 commit comments

Comments
 (0)