2024-07-02 15:09:48 +08:00
|
|
|
import { setCookie, deleteCookie, getCookie } from "cookies-next";
|
2024-07-22 16:07:41 +08:00
|
|
|
import requireAPI from "./requireAPI";
|
2024-08-05 21:10:36 +08:00
|
|
|
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 {
|
2024-07-22 16:07:41 +08:00
|
|
|
const data = await requireAPI("POST", `/api/login/validate`);
|
2024-09-09 15:34:31 +08:00
|
|
|
if (data.ret === 1) {
|
2024-08-06 16:21:34 +08:00
|
|
|
return true;
|
2024-09-09 15:34:31 +08:00
|
|
|
} else {
|
2024-08-06 16:21:34 +08:00
|
|
|
return false;
|
|
|
|
}
|
2024-07-06 11:05:19 +08:00
|
|
|
} catch (e) {
|
2024-09-09 15:34:31 +08:00
|
|
|
// console.log(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
|
|
|
}
|
2024-07-18 23:20:42 +08:00
|
|
|
|
2024-08-05 21:10:36 +08:00
|
|
|
export function checkRole() {
|
|
|
|
const account = get("account");
|
|
|
|
const role = account?.role;
|
|
|
|
const isVip = account?.is_a_member;
|
|
|
|
return role !== 0 || isVip === 1;
|
|
|
|
}
|