Initial commit from saas-meta
This commit is contained in:
36
frontend/src/auth.js
Normal file
36
frontend/src/auth.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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 || '';
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user