From 21c59692f9514f5fc05d428a90d9c8d2ae81d060 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:32:52 +0530 Subject: [PATCH] [WEB-4635] fix: space auth screen re-loading issue (#7551) * fix: prevent auth redirect on window focus * fix: space auth screen re-loading issue. --------- Co-authored-by: Prateek Shourya Co-authored-by: sriram veeraghanta --- apps/space/app/page.tsx | 7 +++---- apps/space/core/store/user.store.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/space/app/page.tsx b/apps/space/app/page.tsx index 7ffff361f..41aeeb18e 100644 --- a/apps/space/app/page.tsx +++ b/apps/space/app/page.tsx @@ -9,12 +9,11 @@ import { AuthView } from "@/components/views"; import { useUser } from "@/hooks/store"; const HomePage = observer(() => { - const { data: currentUser, isAuthenticated, isLoading } = useUser(); + const { data: currentUser, isAuthenticated, isInitializing } = useUser(); - - if (isLoading) + if (isInitializing) return ( -
+
); diff --git a/apps/space/core/store/user.store.ts b/apps/space/core/store/user.store.ts index 438b67aeb..e90cad770 100644 --- a/apps/space/core/store/user.store.ts +++ b/apps/space/core/store/user.store.ts @@ -17,7 +17,7 @@ type TUserErrorStatus = { export interface IUserStore { // observables isAuthenticated: boolean; - isLoading: boolean; + isInitializing: boolean; error: TUserErrorStatus | undefined; data: IUser | undefined; // store observables @@ -35,7 +35,7 @@ export interface IUserStore { export class UserStore implements IUserStore { // observables isAuthenticated: boolean = false; - isLoading: boolean = true; + isInitializing: boolean = true; error: TUserErrorStatus | undefined = undefined; data: IUser | undefined = undefined; // store observables @@ -52,7 +52,7 @@ export class UserStore implements IUserStore { makeObservable(this, { // observables isAuthenticated: observable.ref, - isLoading: observable.ref, + isInitializing: observable.ref, error: observable, // model observables data: observable, @@ -87,7 +87,7 @@ export class UserStore implements IUserStore { fetchCurrentUser = async (): Promise => { try { runInAction(() => { - if (this.data === undefined) this.isLoading = true; + if (this.data === undefined && !this.error) this.isInitializing = true; this.error = undefined; }); const user = await this.userService.me(); @@ -95,19 +95,19 @@ export class UserStore implements IUserStore { await this.profile.fetchUserProfile(); runInAction(() => { this.data = user; - this.isLoading = false; + this.isInitializing = false; this.isAuthenticated = true; }); } else runInAction(() => { this.data = user; - this.isLoading = false; + this.isInitializing = false; this.isAuthenticated = false; }); return user; } catch (error) { runInAction(() => { - this.isLoading = false; + this.isInitializing = false; this.isAuthenticated = false; this.error = { status: "user-fetch-error", @@ -166,7 +166,7 @@ export class UserStore implements IUserStore { reset = (): void => { runInAction(() => { this.isAuthenticated = false; - this.isLoading = false; + this.isInitializing = false; this.error = undefined; this.data = undefined; this.profile = new ProfileStore(this.store);