mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Updated login check method.
This commit is contained in:
parent
170b30b391
commit
796c65fa29
10 changed files with 45 additions and 40 deletions
|
|
@ -1,33 +1,9 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import useStore, { setUser } from 'store/app';
|
||||
import useApi from 'hooks/useApi';
|
||||
|
||||
const selector = state => state.user;
|
||||
let loading = false;
|
||||
|
||||
export default function useUser() {
|
||||
const user = useStore(selector);
|
||||
const { get } = useApi();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
async function loadUser() {
|
||||
const { user } = await get('/auth/verify');
|
||||
loading = false;
|
||||
|
||||
if (!user) {
|
||||
await router.push('/login');
|
||||
} else {
|
||||
setUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
if (!user && !loading) {
|
||||
loading = true;
|
||||
loadUser();
|
||||
}
|
||||
}, [user, get, router]);
|
||||
|
||||
return user;
|
||||
return { user, setUser };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue