tiefen_space_h5/utils/auth.js

33 lines
739 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 true;
}else{
return false;
}
} catch (e) {
console.log(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;
}