mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
[backport cloud/1.41] fix: restore Firebase getAdditionalUserInfo for sign-up telemetry OR logic (#10467)
Backport of #10453 to `cloud/1.41` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10467-backport-cloud-1-41-fix-restore-Firebase-getAdditionalUserInfo-for-sign-up-telemetry--32d6d73d365081daa1fff97d13f29266) by [Unito](https://www.unito.io) Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user