Files
ads-saas/frontend/src/auth.js
2026-03-30 17:04:27 +03:00

37 lines
824 B
JavaScript

/**
* Authentication Helper
* هيلبر المصادقة
*/
export const auth = {
// Current User Key in LocalStorage
STORAGE_KEY: 'saas_user',
// Save user info to local storage
login(user) {
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(user));
return user;
},
// Remove user info (Logout)
logout() {
localStorage.removeItem(this.STORAGE_KEY);
window.location.reload();
},
// Get current user info
getUser() {
const user = localStorage.getItem(this.STORAGE_KEY);
return user ? JSON.parse(user) : null;
},
// Check if user is logged in
isAuthenticated() {
return this.getUser() !== null;
},
// Get User ID for API headers
getUserId() {
return this.getUser()?.id || '';
}
};