Line data Source code
1 : import type { User } from 'firebase/auth'
2 :
3 : import { assert } from '@/base/assert'
4 : import type { operations } from '@/types/comfyRegistryTypes'
5 :
6 : type CreateCustomerResponse =
7 : operations['createCustomer']['responses']['201']['content']['application/json']
8 :
9 : interface AuthStoreAccess {
10 : readonly currentUser: User | null
11 : readonly userEmail: string | null | undefined
12 : getIdToken(): Promise<string | undefined>
13 : createCustomer(): Promise<CreateCustomerResponse>
14 : logout(): Promise<void>
15 : notifyTokenRefreshed(): void
16 : }
17 :
18 2356 : let providedUseAuthStore: (() => AuthStoreAccess) | undefined
19 :
20 : /** Called by `authStore` when it loads. */
21 2356 : export function provideAuthStore(useStore: () => AuthStoreAccess): void {
22 2356 : providedUseAuthStore = useStore
23 : }
24 :
25 : /** `useAuthStore` for the modules `authStore` depends on, which cannot import it back. */
26 2469 : export function useAuthStoreAccess(): AuthStoreAccess {
27 2469 : assert(providedUseAuthStore, 'authStore has not provided itself')
28 2469 : return providedUseAuthStore()
29 : }
|