From c17902c9d463b8b3cc002e25ca31c433d40acb69 Mon Sep 17 00:00:00 2001 From: hetres122 Date: Sun, 1 Oct 2023 16:49:45 +0200 Subject: [PATCH 1/2] After sign out move user to articles page --- .idea/.gitignore | 5 +++++ .idea/inspectionProfiles/Project_Default.xml | 6 ++++++ .idea/vcs.xml | 6 ++++++ system/apps/blog/core/auth/use-auth.ts | 10 +++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..b58b603fe --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..03d9549ea --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/system/apps/blog/core/auth/use-auth.ts b/system/apps/blog/core/auth/use-auth.ts index eaf5d0517..0bfab3f35 100644 --- a/system/apps/blog/core/auth/use-auth.ts +++ b/system/apps/blog/core/auth/use-auth.ts @@ -1,9 +1,13 @@ import { unauthorize, useAuthStore } from '../../store/auth'; import { interceptUnauthorized } from '@system/blog-api'; import { useEffect } from 'react'; +import { useRouter } from 'next/navigation'; +import { useLang } from '../../dk'; const useAuth = () => { const authStore = useAuthStore(); + const router = useRouter(); + const lang = useLang(); useEffect(() => { const { listen, clean } = interceptUnauthorized(unauthorize); @@ -12,11 +16,15 @@ const useAuth = () => { authStore.check(); + if (authStore.key === 'unauthorized') { + router.push(`/${lang}/articles`); + } + return () => { clean(); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [authStore.key]); }; export { useAuth }; From b9963d6db3eea5fb61e3a0f1977fbf4fc0909993 Mon Sep 17 00:00:00 2001 From: hetres122 Date: Sun, 1 Oct 2023 23:48:07 +0200 Subject: [PATCH 2/2] After sign out move user to articles page --- system/apps/blog/core/auth/use-auth.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/system/apps/blog/core/auth/use-auth.ts b/system/apps/blog/core/auth/use-auth.ts index 0bfab3f35..4c3ed5a7a 100644 --- a/system/apps/blog/core/auth/use-auth.ts +++ b/system/apps/blog/core/auth/use-auth.ts @@ -1,8 +1,8 @@ -import { unauthorize, useAuthStore } from '../../store/auth'; -import { interceptUnauthorized } from '@system/blog-api'; -import { useEffect } from 'react'; -import { useRouter } from 'next/navigation'; -import { useLang } from '../../dk'; +import {unauthorize, useAuthStore} from '../../store/auth'; +import {interceptUnauthorized} from '@system/blog-api'; +import {useEffect} from 'react'; +import {useRouter} from 'next/navigation'; +import {useLang} from '../../dk'; const useAuth = () => { const authStore = useAuthStore(); @@ -10,16 +10,15 @@ const useAuth = () => { const lang = useLang(); useEffect(() => { - const { listen, clean } = interceptUnauthorized(unauthorize); - + const {listen, clean} = interceptUnauthorized(() => { + unauthorize(); + router.push(`/${lang}/articles`); + }); listen(); - authStore.check(); - if (authStore.key === 'unauthorized') { - router.push(`/${lang}/articles`); - } - + router.push(`/${lang}/articles`); + return () => { clean(); }; @@ -27,4 +26,4 @@ const useAuth = () => { }, [authStore.key]); }; -export { useAuth }; +export {useAuth};