Add MSW, implement lazy token validation, and create failing tests for offline Firebase handling

Co-authored-by: snomiao <7323030+snomiao@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-07-31 03:18:30 +00:00
parent 3861e0068f
commit 0cdb56e023
4 changed files with 544 additions and 48 deletions

View File

@@ -90,7 +90,21 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
const getIdToken = async (): Promise<string | null> => {
if (currentUser.value) {
return currentUser.value.getIdToken()
try {
return await currentUser.value.getIdToken()
} catch (error: any) {
// Handle network-related Firebase Auth errors gracefully
if (error?.code === 'auth/network-request-failed' ||
error?.message?.includes('network') ||
error?.message?.includes('Network error') ||
error?.message?.includes('A network error has occurred')) {
// Return null for network errors to allow offline functionality
console.warn('Firebase Auth network error, working offline:', error.message)
return null
}
// Re-throw other errors as they might be important
throw error
}
}
return null
}