From 59eb0265bfaf204a0ffdfb45cb3634b1ca7c52c0 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 10 Jan 2024 15:39:02 +0300 Subject: [PATCH] get-author-fix --- package.json | 3 +-- src/components/AuthGuard/AuthGuard.tsx | 10 ++++++++-- src/context/session.tsx | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ba7d22ec..40bb8347 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,7 @@ "lint:styles": "stylelint **/*.{scss,css}", "lint:styles:fix": "stylelint **/*.{scss,css} --fix", "pre-commit": "lint-staged", - "pre-push": "", - "pre-push-old": "npm run typecheck", + "pre-push": "npm run typecheck", "prepare": "husky install", "preview": "vite preview", "start": "vite", diff --git a/src/components/AuthGuard/AuthGuard.tsx b/src/components/AuthGuard/AuthGuard.tsx index d4e2e133..73144eb0 100644 --- a/src/components/AuthGuard/AuthGuard.tsx +++ b/src/components/AuthGuard/AuthGuard.tsx @@ -12,10 +12,14 @@ type Props = { } export const AuthGuard = (props: Props) => { - const { isAuthenticated, isSessionLoaded } = useSession() + const { + isAuthenticated, + isSessionLoaded, + actions: { loadSession }, + } = useSession() const { changeSearchParams } = useRouter() - createEffect(() => { + createEffect(async () => { if (props.disabled) { return } @@ -31,6 +35,8 @@ export const AuthGuard = (props: Props) => { true, ) } + } else { + await loadSession() } }) diff --git a/src/context/session.tsx b/src/context/session.tsx index 9633ac30..5398d554 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -128,7 +128,7 @@ export const SessionProvider = (props: { const [author, { refetch: loadAuthor, mutate: setAuthor }] = createResource( async () => { const u = session()?.user - return u ? (await apiClient.getAuthorId({ user: u.id })) || null : null + return u ? (await apiClient.getAuthorId({ user: u.id.trim() })) || null : null }, { ssrLoadFrom: 'initial',