tiefen_space_h5/utils/auth.js

31 lines
727 B
JavaScript

import { setCookie, deleteCookie, getCookie } from "cookies-next";
import requireAPI from "./requireAPI";
import {get} from "./storeInfo"
export async function checkAuth() {
try {
const data = await requireAPI("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);
};