Assign user to userStore

This commit is contained in:
Brian Cao 2022-11-09 13:54:09 -08:00
parent 84375a582e
commit 7bf12cc552
2 changed files with 9 additions and 4 deletions

View File

@ -42,9 +42,11 @@ export default function LoginForm() {
});
if (ok) {
setItem(AUTH_TOKEN, data.token);
const { user, token } = data;
setUser(data.user);
setItem(AUTH_TOKEN, token);
setUser(user);
await router.push('/');

View File

@ -12,14 +12,17 @@ export default function useRequireLogin() {
async function loadUser() {
setLoading(true);
const { ok, data } = await get('/auth/verify');
const {
ok,
data: { user },
} = await get('/auth/verify');
if (!ok) {
await router.push('/login');
return null;
}
setUser(data);
setUser(user);
setLoading(false);
}