33 lines
820 B
JavaScript
33 lines
820 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, { maxAge: 60 * 60 * 24 * 365 * 10 });
|
|
setCookie("mid", data.data.account.mid, { maxAge: 60 * 60 * 24 * 365 * 10 });
|
|
}
|
|
|
|
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;
|
|
}
|