Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ vi.mock('@primevue/forms', () => ({
}
}))

vi.mock('@/stores/firebaseAuthStore', () => ({
useFirebaseAuthStore: () => ({
currentUser: {
email: 'test@example.com'
}
})
}))

describe('ReportIssuePanel', () => {
beforeEach(() => {
vi.clearAllMocks()
Expand Down
31 changes: 15 additions & 16 deletions src/stores/firebaseAuthStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,21 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
const userId = computed(() => currentUser.value?.uid)

// Get auth from VueFire and listen for auth state changes
const auth = useFirebaseAuth()
if (auth) {
// Set persistence to localStorage (works in both browser and Electron)
void setPersistence(auth, browserLocalPersistence)

onAuthStateChanged(auth, (user) => {
currentUser.value = user
isInitialized.value = true

// Reset balance when auth state changes
balance.value = null
lastBalanceUpdateTime.value = null
})
} else {
error.value = 'Firebase Auth not available from VueFire'
}
// From useFirebaseAuth docs:
// 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
isInitialized.value = true

// Reset balance when auth state changes
balance.value = null
lastBalanceUpdateTime.value = null
})

const showAuthErrorToast = () => {
useToastStore().add({
Expand Down
17 changes: 0 additions & 17 deletions tests-ui/tests/store/firebaseAuthStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,6 @@ describe('useFirebaseAuthStore', () => {
expect(store.error).toBe(null)
})

it('should handle auth initialization failure', async () => {
// Mock auth as null to simulate initialization failure
vi.mocked(vuefire.useFirebaseAuth).mockReturnValue(null)

// Create a new store instance
setActivePinia(createPinia())
const uninitializedStore = useFirebaseAuthStore()

// Check that isInitialized is false
expect(uninitializedStore.isInitialized).toBe(false)

// Verify store actions throw appropriate errors
await expect(
uninitializedStore.login('test@example.com', 'password')
).rejects.toThrow('Firebase Auth not initialized')
})

describe('login', () => {
it('should login with valid credentials', async () => {
const mockUserCredential = { user: mockUser }
Expand Down