37 lines
824 B
JavaScript
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 || '';
|
|
}
|
|
};
|