31 lines
718 B
JavaScript
31 lines
718 B
JavaScript
import { setCookie, deleteCookie, getCookie } from "cookies-next";
|
|
import require from "./require";
|
|
import {get} from "./storeInfo"
|
|
export async function checkAuth() {
|
|
try {
|
|
const data = await require("POST", `/api/login/validate`);
|
|
if (data.ret === -1) {
|
|
return false;
|
|
}
|
|
return true;
|
|
} catch (e) {
|
|
console.warn(e);
|
|
}
|
|
}
|
|
|
|
export function signIn(data) {
|
|
setCookie("token", data.data.token);
|
|
setCookie("mid", data.data.account.mid);
|
|
}
|
|
|
|
export function signOut() {
|
|
deleteCookie("token");
|
|
deleteCookie("mid");
|
|
}
|
|
|
|
export function checkRole(){
|
|
const account = get("account");
|
|
const role = account.role;
|
|
const isVip = account.is_a_member;
|
|
return (role !== 0 || isVip === 1);
|
|
}; |