test new login
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import Cookie from "js-cookie";
|
||||
|
||||
export function isEmail(input: string): boolean {
|
||||
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
||||
return emailRegex.test(input);
|
||||
@@ -29,3 +31,43 @@ export const timeAgo = (date: string | Date): string => {
|
||||
|
||||
return "همین الان";
|
||||
};
|
||||
|
||||
export const getToken = () => {
|
||||
return Cookie.get(import.meta.env.VITE_TOKEN_NAME);
|
||||
};
|
||||
|
||||
export const getRefreshToken = () => {
|
||||
return Cookie.get(import.meta.env.VITE_REFRESH_TOKEN_NAME);
|
||||
};
|
||||
|
||||
export const setToken = (token: string) => {
|
||||
Cookie.set(import.meta.env.VITE_TOKEN_NAME, token, {
|
||||
domain: ".danakcorp.com",
|
||||
path: "/",
|
||||
secure: true, // فقط روی HTTPS کار میکنه
|
||||
sameSite: "Strict", // جلوگیری از حملات CSRF
|
||||
});
|
||||
};
|
||||
|
||||
export const setRefreshToken = (refreshToken: string) => {
|
||||
Cookie.set(import.meta.env.VITE_REFRESH_TOKEN_NAME, refreshToken, {
|
||||
domain: ".danakcorp.com",
|
||||
path: "/",
|
||||
secure: true,
|
||||
sameSite: "Strict",
|
||||
});
|
||||
};
|
||||
|
||||
export const removeToken = () => {
|
||||
Cookie.remove(import.meta.env.VITE_TOKEN_NAME, {
|
||||
domain: ".danakcorp.com",
|
||||
path: "/",
|
||||
});
|
||||
};
|
||||
|
||||
export const removeRefreshToken = () => {
|
||||
Cookie.remove(import.meta.env.VITE_REFRESH_TOKEN_NAME, {
|
||||
domain: ".danakcorp.com",
|
||||
path: "/",
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user