tiefen_space_h5/utils/auth.js

31 lines
718 B
JavaScript
Raw Normal View History

2024-07-02 15:09:48 +08:00
import { setCookie, deleteCookie, getCookie } from "cookies-next";
2024-07-06 11:05:19 +08:00
import require from "./require";
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 {
const data = await require("POST", `/api/login/validate`);
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);
};