From 8bab85ddc1948bb1b64cedaaf3fa0b37a24d66c3 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 1 Aug 2024 16:21:36 +0500 Subject: [PATCH] fix?: rerender when auth check finished --- app/store/auth.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/store/auth.ts b/app/store/auth.ts index 45c4364..1489174 100644 --- a/app/store/auth.ts +++ b/app/store/auth.ts @@ -23,17 +23,20 @@ export const useUserStore = create((set, get) => ({ set({ isAuth: false, user: null, token: null }); removeJWT(); }, - checkAuth: async () => { + checkAuth: () => { const jwt = getJWT(); if (jwt) { - const data = await fetchDataViaGet( - `/api/profile/${jwt.user_id}?token=${jwt.jwt}` - ); - if (data && data.is_my_profile) { - get().login(data.profile, jwt.jwt); - } else { - get().logout(); + const _checkAuth = async () => { + const data = await fetchDataViaGet( + `/api/profile/${jwt.user_id}?token=${jwt.jwt}` + ); + if (data && data.is_my_profile) { + get().login(data.profile, jwt.jwt); + } else { + get().logout(); + } } + _checkAuth() } else { get().logout(); }