Add enums, AuthService, and integrate backend registration endpoints
All checks were successful
Build frontend / build (push) Successful in 57s
All checks were successful
Build frontend / build (push) Successful in 57s
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType - Add AuthService (addToken/getToken/deleteToken) - Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints - Update login page to use AuthService for token storage - Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification - Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification - Update homepage and property detail to use enums instead of hardcoded maps - Update AddPropertyForm to import from enums directly - Add console logs and status toasts linked to API response messages
This commit is contained in:
51
app/services/AuthService.js
Normal file
51
app/services/AuthService.js
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* AuthService
|
||||
* Manages authentication tokens securely using localStorage.
|
||||
*
|
||||
* Methods:
|
||||
* addToken(token) — store JWT token
|
||||
* getToken() — retrieve JWT token
|
||||
* deleteToken() — remove JWT token
|
||||
*
|
||||
* Usage:
|
||||
* import AuthService from '@/app/services/AuthService';
|
||||
* AuthService.addToken(token);
|
||||
* const token = AuthService.getToken();
|
||||
* AuthService.deleteToken();
|
||||
*/
|
||||
const TOKEN_KEY = 'auth_token';
|
||||
|
||||
const AuthService = Object.freeze({
|
||||
/**
|
||||
* Store token in localStorage
|
||||
* @param {string} token — JWT string
|
||||
*/
|
||||
addToken(token) {
|
||||
if (!token || typeof token !== 'string') {
|
||||
console.error('[AuthService] addToken: invalid token', token);
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(TOKEN_KEY, token);
|
||||
console.log('[AuthService] Token stored');
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve token from localStorage
|
||||
* @returns {string|null}
|
||||
*/
|
||||
getToken() {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
console.log('[AuthService] getToken:', token ? '***exists***' : null);
|
||||
return token;
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove token from localStorage
|
||||
*/
|
||||
deleteToken() {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
console.log('[AuthService] Token deleted');
|
||||
},
|
||||
});
|
||||
|
||||
export default AuthService;
|
||||
Reference in New Issue
Block a user