@@ -6,20 +6,13 @@ import { ANALYTICS_EVENTS } from "@shared/types/analytics";
66import type { CloudRegion } from "@shared/types/regions" ;
77import { getCloudUrlFromRegion } from "@shared/utils/urls" ;
88import { useNavigationStore } from "@stores/navigationStore" ;
9- import {
10- identifyUser ,
11- isFeatureFlagEnabled ,
12- resetUser ,
13- track ,
14- } from "@utils/analytics" ;
9+ import { identifyUser , resetUser , track } from "@utils/analytics" ;
1510import { logger } from "@utils/logger" ;
1611import { queryClient } from "@utils/queryClient" ;
1712import { create } from "zustand" ;
1813
1914const log = logger . scope ( "auth-store" ) ;
2015
21- let initializePromise : Promise < boolean > | null = null ;
22- let authStateSubscription : { unsubscribe : ( ) => void } | null = null ;
2316let sessionResetCallback : ( ( ) => void ) | null = null ;
2417let inFlightAuthSync : Promise < void > | null = null ;
2518let inFlightAuthSyncKey : string | null = null ;
@@ -30,8 +23,6 @@ export function setSessionResetCallback(callback: () => void) {
3023}
3124
3225export function resetAuthStoreModuleStateForTest ( ) : void {
33- initializePromise = null ;
34- authStateSubscription = null ;
3526 sessionResetCallback = null ;
3627 inFlightAuthSync = null ;
3728 inFlightAuthSyncKey = null ;
@@ -56,9 +47,7 @@ interface AuthStoreState {
5647 redeemInviteCode : ( code : string ) => Promise < void > ;
5748 loginWithOAuth : ( region : CloudRegion ) => Promise < void > ;
5849 signupWithOAuth : ( region : CloudRegion ) => Promise < void > ;
59- initializeOAuth : ( ) => Promise < boolean > ;
6050 selectProject : ( projectId : number ) => Promise < void > ;
61- completeOnboarding : ( ) => void ;
6251 selectPlan : ( plan : "free" | "pro" ) => void ;
6352 selectOrg : ( orgId : string ) => void ;
6453 logout : ( ) => Promise < void > ;
@@ -204,22 +193,7 @@ async function syncAuthState(): Promise<void> {
204193 await inFlightAuthSync ;
205194}
206195
207- function ensureAuthSubscription ( ) : void {
208- if ( authStateSubscription ) {
209- return ;
210- }
211-
212- authStateSubscription = trpcClient . auth . onStateChanged . subscribe ( undefined , {
213- onData : ( ) => {
214- void syncAuthState ( ) ;
215- } ,
216- onError : ( error ) => {
217- log . error ( "Auth state subscription error" , { error } ) ;
218- } ,
219- } ) ;
220- }
221-
222- export const useAuthStore = create < AuthStoreState > ( ( set , get ) => ( {
196+ export const useAuthStore = create < AuthStoreState > ( ( set , _get ) => ( {
223197 cloudRegion : null ,
224198 staleCloudRegion : null ,
225199
@@ -263,39 +237,13 @@ export const useAuthStore = create<AuthStoreState>((set, get) => ({
263237 } ) ;
264238 } ,
265239
266- initializeOAuth : async ( ) => {
267- if ( initializePromise ) {
268- return initializePromise ;
269- }
270-
271- initializePromise = ( async ( ) => {
272- ensureAuthSubscription ( ) ;
273- await syncAuthState ( ) ;
274- return get ( ) . isAuthenticated || get ( ) . needsScopeReauth ;
275- } ) ( ) . finally ( ( ) => {
276- initializePromise = null ;
277- } ) ;
278-
279- return initializePromise ;
280- } ,
281-
282240 selectProject : async ( projectId : number ) => {
283241 sessionResetCallback ?.( ) ;
284242 await trpcClient . auth . selectProject . mutate ( { projectId } ) ;
285243 await syncAuthState ( ) ;
286244 useNavigationStore . getState ( ) . navigateToTaskInput ( ) ;
287245 } ,
288246
289- completeOnboarding : ( ) => {
290- set ( { hasCompletedOnboarding : true } ) ;
291- if (
292- isFeatureFlagEnabled ( "posthog-code-billing" ) &&
293- ! useSeatStore . getState ( ) . seat
294- ) {
295- useSeatStore . getState ( ) . provisionFreeSeat ( ) ;
296- }
297- } ,
298-
299247 selectPlan : ( plan : "free" | "pro" ) => {
300248 set ( { selectedPlan : plan } ) ;
301249 } ,
0 commit comments