mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-01 03:31:58 +00:00
[API Node] Set auth persistence in local stoarge (#3514)
This commit is contained in:
@@ -4,8 +4,10 @@ import {
|
|||||||
GoogleAuthProvider,
|
GoogleAuthProvider,
|
||||||
type User,
|
type User,
|
||||||
type UserCredential,
|
type UserCredential,
|
||||||
|
browserLocalPersistence,
|
||||||
createUserWithEmailAndPassword,
|
createUserWithEmailAndPassword,
|
||||||
onAuthStateChanged,
|
onAuthStateChanged,
|
||||||
|
setPersistence,
|
||||||
signInWithEmailAndPassword,
|
signInWithEmailAndPassword,
|
||||||
signInWithPopup,
|
signInWithPopup,
|
||||||
signOut
|
signOut
|
||||||
@@ -33,6 +35,9 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
|
|||||||
// Get auth from VueFire and listen for auth state changes
|
// Get auth from VueFire and listen for auth state changes
|
||||||
const auth = useFirebaseAuth()
|
const auth = useFirebaseAuth()
|
||||||
if (auth) {
|
if (auth) {
|
||||||
|
// Set persistence to localStorage (works in both browser and Electron)
|
||||||
|
void setPersistence(auth, browserLocalPersistence)
|
||||||
|
|
||||||
onAuthStateChanged(auth, (user) => {
|
onAuthStateChanged(auth, (user) => {
|
||||||
currentUser.value = user
|
currentUser.value = user
|
||||||
isInitialized.value = true
|
isInitialized.value = true
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ vi.mock('firebase/auth', () => ({
|
|||||||
onAuthStateChanged: vi.fn(),
|
onAuthStateChanged: vi.fn(),
|
||||||
signInWithPopup: vi.fn(),
|
signInWithPopup: vi.fn(),
|
||||||
GoogleAuthProvider: vi.fn(),
|
GoogleAuthProvider: vi.fn(),
|
||||||
GithubAuthProvider: vi.fn()
|
GithubAuthProvider: vi.fn(),
|
||||||
|
browserLocalPersistence: 'browserLocalPersistence',
|
||||||
|
setPersistence: vi.fn().mockResolvedValue(undefined)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe('useFirebaseAuthStore', () => {
|
describe('useFirebaseAuthStore', () => {
|
||||||
@@ -64,6 +66,13 @@ describe('useFirebaseAuthStore', () => {
|
|||||||
expect(store.error).toBe(null)
|
expect(store.error).toBe(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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 () => {
|
it('should properly clean up error state between operations', async () => {
|
||||||
// First, cause an error
|
// First, cause an error
|
||||||
const mockError = new Error('Invalid password')
|
const mockError = new Error('Invalid password')
|
||||||
|
|||||||
Reference in New Issue
Block a user