fixd larg lines in HomePage , add cookies rather than localStorage,make canvas background Login page

This commit is contained in:
hamzaobed7
2026-08-04 12:51:47 +03:00
parent 4ebb75ddd9
commit 7973c15e3f
51 changed files with 1460 additions and 2563 deletions

View File

@ -1,3 +1,4 @@
import Cookies from "js-cookie";
/**
* AuthService
* Manages authentication tokens and user role detection via JWT decoding.
@ -20,22 +21,28 @@
* isAuthenticated() — check if token exists
*/
const TOKEN_KEY = 'auth_token';
const USER_KEY = 'cached_user';
const TOKEN_KEY = "auth_token";
const USER_KEY = "cached_user";
const AuthService = Object.freeze({
addToken(token) {
if (!token || typeof token !== 'string') return;
localStorage.setItem(TOKEN_KEY, token);
if (!token || typeof token !== "string") return;
Cookies.set(TOKEN_KEY, token, {
expires: 7,
secure: true,
sameSite: "lax",
path: "/",
});
},
getToken() {
return localStorage.getItem(TOKEN_KEY);
if (typeof window === "undefined") return null;
return Cookies.get(TOKEN_KEY);
},
deleteToken() {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
Cookies.remove(TOKEN_KEY);
},
/**
@ -67,7 +74,7 @@ const AuthService = Object.freeze({
const token = this.getToken();
if (!token) return null;
try {
const payload = token.split('.')[1];
const payload = token.split(".")[1];
return JSON.parse(atob(payload));
} catch {
return null;
@ -85,10 +92,10 @@ const AuthService = Object.freeze({
const cached = this.getCachedUser();
return {
id: payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'] || payload.sub || null,
name: cached?.name || payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'] || null,
email: cached?.email || payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] || null,
phone: cached?.phone || payload['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone'] || null,
id: payload["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"] || payload.sub || null,
name: cached?.name || payload["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"] || null,
email: cached?.email || payload["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"] || null,
phone: cached?.phone || payload["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone"] || null,
roles: this.getRoles(),
};
},
@ -112,9 +119,9 @@ const AuthService = Object.freeze({
getRoles() {
const payload = this.decodeToken();
if (!payload) return [];
const roles = payload['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'];
const roles = payload["http://schemas.microsoft.com/ws/2008/06/identity/claims/role"];
if (Array.isArray(roles)) return roles;
if (typeof roles === 'string') return [roles];
if (typeof roles === "string") return [roles];
return [];
},
@ -123,7 +130,7 @@ const AuthService = Object.freeze({
* @returns {boolean}
*/
isOwner() {
return this.getRoles().includes('Owner');
return this.getRoles().includes("Owner");
},
/**
@ -131,7 +138,7 @@ const AuthService = Object.freeze({
* @returns {boolean}
*/
isAgent() {
return this.getRoles().includes('RealEstateAgent');
return this.getRoles().includes("RealEstateAgent");
},
/**
@ -160,4 +167,3 @@ const AuthService = Object.freeze({
});
export default AuthService;