fix: restore firebaseAuthStore to main version

Stale version was carried over from pre-rebase branch.
This commit is contained in:
bymyself
2026-03-24 13:28:50 -07:00
parent 82595f5704
commit e540920fbb
2 changed files with 92 additions and 2 deletions

View File

@@ -85,10 +85,19 @@ vi.mock('firebase/auth', async (importOriginal) => {
addScope = vi.fn()
setCustomParameters = vi.fn()
},
getAdditionalUserInfo: vi.fn(),
setPersistence: vi.fn().mockResolvedValue(undefined)
}
})
// Mock telemetry
const mockTrackAuth = vi.fn()
vi.mock('@/platform/telemetry', () => ({
useTelemetry: () => ({
trackAuth: mockTrackAuth
})
}))
// Mock useToastStore
vi.mock('@/stores/toastStore', () => ({
useToastStore: () => ({
@@ -572,6 +581,82 @@ describe('useFirebaseAuthStore', () => {
expect(store.loading).toBe(false)
})
describe('sign-up telemetry OR logic', () => {
const mockUserCredential = {
user: mockUser
} as Partial<UserCredential> as UserCredential
beforeEach(() => {
vi.mocked(firebaseAuth.signInWithPopup).mockResolvedValue(
mockUserCredential
)
})
it.each(['loginWithGoogle', 'loginWithGithub'] as const)(
'%s should track is_new_user=true when Firebase says new user',
async (method) => {
vi.mocked(firebaseAuth.getAdditionalUserInfo).mockReturnValue({
isNewUser: true,
providerId: 'google.com',
profile: null
})
await store[method]()
expect(mockTrackAuth).toHaveBeenCalledWith(
expect.objectContaining({ is_new_user: true })
)
}
)
it.each(['loginWithGoogle', 'loginWithGithub'] as const)(
'%s should track is_new_user=true when UI options say new user',
async (method) => {
vi.mocked(firebaseAuth.getAdditionalUserInfo).mockReturnValue({
isNewUser: false,
providerId: 'google.com',
profile: null
})
await store[method]({ isNewUser: true })
expect(mockTrackAuth).toHaveBeenCalledWith(
expect.objectContaining({ is_new_user: true })
)
}
)
it.each(['loginWithGoogle', 'loginWithGithub'] as const)(
'%s should track is_new_user=false when neither source says new user',
async (method) => {
vi.mocked(firebaseAuth.getAdditionalUserInfo).mockReturnValue({
isNewUser: false,
providerId: 'google.com',
profile: null
})
await store[method]()
expect(mockTrackAuth).toHaveBeenCalledWith(
expect.objectContaining({ is_new_user: false })
)
}
)
it.each(['loginWithGoogle', 'loginWithGithub'] as const)(
'%s should track is_new_user=false when getAdditionalUserInfo returns null',
async (method) => {
vi.mocked(firebaseAuth.getAdditionalUserInfo).mockReturnValue(null)
await store[method]()
expect(mockTrackAuth).toHaveBeenCalledWith(
expect.objectContaining({ is_new_user: false })
)
}
)
})
})
describe('accessBillingPortal', () => {

View File

@@ -5,6 +5,7 @@ import {
GoogleAuthProvider,
browserLocalPersistence,
createUserWithEmailAndPassword,
getAdditionalUserInfo,
onAuthStateChanged,
onIdTokenChanged,
sendPasswordResetEmail,
@@ -386,9 +387,11 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
)
if (isCloud) {
const additionalUserInfo = getAdditionalUserInfo(result)
useTelemetry()?.trackAuth({
method: 'google',
is_new_user: options?.isNewUser ?? false,
is_new_user:
options?.isNewUser || additionalUserInfo?.isNewUser || false,
user_id: result.user.uid
})
}
@@ -405,9 +408,11 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => {
)
if (isCloud) {
const additionalUserInfo = getAdditionalUserInfo(result)
useTelemetry()?.trackAuth({
method: 'github',
is_new_user: options?.isNewUser ?? false,
is_new_user:
options?.isNewUser || additionalUserInfo?.isNewUser || false,
user_id: result.user.uid
})
}