mirror of
https://github.com/Radiquum/AniX.git
synced 2025-05-02 02:49:40 +05:00
Back and Front: User Login
This commit is contained in:
parent
a03deddbc0
commit
32a4da1a31
8 changed files with 141 additions and 36 deletions
|
@ -7,20 +7,24 @@ export const useUserStore = create((set, get) => ({
|
|||
isAuth: false,
|
||||
user: null,
|
||||
token: null,
|
||||
login: (user, token) => {
|
||||
|
||||
login: (user, token, user_id) => {
|
||||
set({ isAuth: true, user, token });
|
||||
setJWT(token);
|
||||
setJWT(token, user_id);
|
||||
},
|
||||
logout: () => {
|
||||
set({ isAuth: false, user: null, token: null });
|
||||
removeJWT();
|
||||
},
|
||||
checkAuth: async (user_id) => {
|
||||
checkAuth: async () => {
|
||||
const jwt = getJWT();
|
||||
if (jwt) {
|
||||
const me = await getMe(`${endpoints.profile}/${user_id}`, jwt);
|
||||
const me = await getMe(
|
||||
`${endpoints.user.profile}/${jwt.user_id}`,
|
||||
jwt.jwt,
|
||||
);
|
||||
if (me.is_my_profile) {
|
||||
get().login(me, jwt);
|
||||
get().login(me, jwt.jwt, jwt.user_id);
|
||||
} else {
|
||||
get().logout();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue