feat: self-serve signup Phase 2 (frontend cutover) (#162)
Co-authored-by: Michael Chihlas <michael@resolutionflow.com> Co-committed-by: Michael Chihlas <michael@resolutionflow.com>
This commit was merged in pull request #162.
This commit is contained in:
@@ -6,6 +6,7 @@ import { authApi } from '@/api/auth'
|
||||
import { identifyUser, resetAnalytics, analytics } from '@/lib/analytics'
|
||||
import { apiClient } from '@/api/client'
|
||||
import { clearCachedQuota } from '@/hooks/useCachedQuota'
|
||||
import { useBillingStore } from '@/store/billingStore'
|
||||
|
||||
interface AuthState {
|
||||
user: User | null
|
||||
@@ -85,6 +86,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
localStorage.removeItem('access_token')
|
||||
localStorage.removeItem('refresh_token')
|
||||
clearCachedQuota()
|
||||
useBillingStore.getState().reset()
|
||||
Sentry.setUser(null)
|
||||
resetAnalytics()
|
||||
set({ user: null, token: null, account: null, subscription: null, isAuthenticated: false, error: null })
|
||||
@@ -117,6 +119,11 @@ export const useAuthStore = create<AuthState>()(
|
||||
identifyUser({ id: user.id, email: user.email, role: user.role, is_super_admin: user.is_super_admin, account_id: account?.id })
|
||||
|
||||
set({ user, account, subscription, isLoading: false })
|
||||
|
||||
// Kick off billing-state fetch alongside auth — fire-and-forget so
|
||||
// a billing error never breaks login. The billing store records
|
||||
// its own error state.
|
||||
void useBillingStore.getState().fetch()
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to fetch user'
|
||||
set({ error: message, isLoading: false })
|
||||
@@ -124,7 +131,13 @@ export const useAuthStore = create<AuthState>()(
|
||||
}
|
||||
},
|
||||
|
||||
setTokens: (token: Token) => set({ token }),
|
||||
// Storing tokens implies an active session — mark the store as
|
||||
// authenticated so <ProtectedRoute> doesn't bounce the user back to
|
||||
// /landing while fetchUser() is still inflight (e.g. immediately after
|
||||
// the OAuth callback exchange). The refresh interceptor in api/client.ts
|
||||
// also calls this; that path is already authenticated, so flipping the
|
||||
// flag has no effect there.
|
||||
setTokens: (token: Token) => set({ token, isAuthenticated: true }),
|
||||
clearError: () => set({ error: null }),
|
||||
setLoading: (loading: boolean) => set({ isLoading: loading }),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user