Prevent change the cookie from javascript or console.log in the browser
So I have some composable named
useAuthuseAuth served as the provider to set, get, and remove the token from cookie. But I want this cookie can't be changed from the browser or console.log, is it possible?export default function useAuth() {
const setAuthorizationToken = async (val: string, expiresAt?: any) => {
let expiryDate: Date;
if (!expiresAt) {
// Default expiration: 1 month from now
expiryDate = new Date();
expiryDate.setMonth(expiryDate.getMonth() + 1);
} else if (typeof expiresAt === "string" || typeof expiresAt === "number") {
// Parse `expiresAt` if it's a timestamp or ISO string
expiryDate = new Date(expiresAt);
} else if (expiresAt instanceof Date) {
// Use `expiresAt` directly if it's already a Date object
expiryDate = expiresAt;
} else {
throw new Error("Invalid expiresAt format. Expected a Date, timestamp, or ISO string.");
}
const token = useCookie("_at", {
path: "/",
expires: expiryDate,
sameSite: "strict", // Tidak dikirim ke domain lain
});
token.value = val;
}
}export default function useAuth() {
const setAuthorizationToken = async (val: string, expiresAt?: any) => {
let expiryDate: Date;
if (!expiresAt) {
// Default expiration: 1 month from now
expiryDate = new Date();
expiryDate.setMonth(expiryDate.getMonth() + 1);
} else if (typeof expiresAt === "string" || typeof expiresAt === "number") {
// Parse `expiresAt` if it's a timestamp or ISO string
expiryDate = new Date(expiresAt);
} else if (expiresAt instanceof Date) {
// Use `expiresAt` directly if it's already a Date object
expiryDate = expiresAt;
} else {
throw new Error("Invalid expiresAt format. Expected a Date, timestamp, or ISO string.");
}
const token = useCookie("_at", {
path: "/",
expires: expiryDate,
sameSite: "strict", // Tidak dikirim ke domain lain
});
token.value = val;
}
}