Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion system/apps/blog/core/auth/use-auth.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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 };