tiefen_space_h5/utils/auth.js

31 lines
727 B
JavaScript
Raw Normal View History

2024-07-02 15:09:48 +08:00
import { setCookie, deleteCookie, getCookie } from "cookies-next";
2024-07-22 16:07:41 +08:00
import requireAPI from "./requireAPI";
import {get} from "./storeInfo"
2024-07-02 15:09:48 +08:00
export async function checkAuth() {
2024-07-06 11:05:19 +08:00
try {
2024-07-22 16:07:41 +08:00
const data = await requireAPI("POST", `/api/login/validate`);
2024-07-06 11:05:19 +08:00
if (data.ret === -1) {
return false;
2024-07-02 15:09:48 +08:00
}
2024-07-06 11:05:19 +08:00
return true;
} catch (e) {
console.warn(e);
2024-07-02 15:09:48 +08:00
}
}
export function signIn(data) {
setCookie("token", data.data.token);
2024-07-06 11:05:19 +08:00
setCookie("mid", data.data.account.mid);
2024-07-02 15:09:48 +08:00
}
export function signOut() {
deleteCookie("token");
2024-07-06 11:05:19 +08:00
deleteCookie("mid");
2024-07-02 15:09:48 +08:00
}
export function checkRole(){
const account = get("account");
const role = account.role;
const isVip = account.is_a_member;
return (role !== 0 || isVip === 1);
};