tiefen_space_h5/utils/auth.js

24 lines
515 B
JavaScript

import { setCookie, deleteCookie, getCookie } from "cookies-next";
import require from "./require";
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");
}