This commit is contained in:
@ -25,12 +25,15 @@ import { getCustomerByUserId, getOwnerByUserId, loginWithEmail, loginWithPhone }
|
|||||||
const TOKEN_KEY = "auth_token";
|
const TOKEN_KEY = "auth_token";
|
||||||
const USER_KEY = "cached_user";
|
const USER_KEY = "cached_user";
|
||||||
|
|
||||||
|
const isSecureContext = () =>
|
||||||
|
typeof window !== "undefined" && window.location?.protocol === "https:";
|
||||||
|
|
||||||
const AuthService = Object.freeze({
|
const AuthService = Object.freeze({
|
||||||
addToken(token) {
|
addToken(token) {
|
||||||
if (!token || typeof token !== "string") return;
|
if (!token || typeof token !== "string") return;
|
||||||
Cookies.set(TOKEN_KEY, token, {
|
Cookies.set(TOKEN_KEY, token, {
|
||||||
expires: 7,
|
expires: 7,
|
||||||
secure: true,
|
secure: isSecureContext(),
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
path: "/",
|
path: "/",
|
||||||
});
|
});
|
||||||
@ -51,7 +54,7 @@ const AuthService = Object.freeze({
|
|||||||
cacheUser(user) {
|
cacheUser(user) {
|
||||||
Cookies.set(USER_KEY, JSON.stringify(user), {
|
Cookies.set(USER_KEY, JSON.stringify(user), {
|
||||||
expires: 7,
|
expires: 7,
|
||||||
secure: true,
|
secure: isSecureContext(),
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
path: "/",
|
path: "/",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user