[Cleanup] Remove unnecessary null check on auth (#3610)

This commit is contained in:
Chenlei Hu
2025-04-24 17:36:16 -04:00
committed by GitHub
parent 31d5671f24
commit 0ed29a198d
3 changed files with 21 additions and 31 deletions

View File

@@ -142,6 +142,14 @@ vi.mock('@primevue/forms', () => ({
}
}))
vi.mock('@/stores/firebaseAuthStore', () => ({
useFirebaseAuthStore: () => ({
currentUser: {
email: 'test@example.com'
}
})
}))
describe('ReportIssuePanel', () => {
beforeEach(() => {
vi.clearAllMocks()

View File

@@ -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)
// 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
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'
}
// Reset balance when auth state changes
balance.value = null
lastBalanceUpdateTime.value = null
})
const showAuthErrorToast = () => {
useToastStore().add({