feat: implement logout functionality and enhance contact layout

This commit is contained in:
2025-11-17 13:35:33 +05:30
parent 38f305067a
commit e83e2b2161
13 changed files with 205 additions and 133 deletions
+24 -23
View File
@@ -25,6 +25,7 @@ export class AuthService {
router = inject(Router);
private readonly storageKey = 'accessToken';
tokenReady$ = new BehaviorSubject<boolean | null>(null);
constructor() {
console.log('🔥 AuthService constructor started');
@@ -36,31 +37,31 @@ export class AuthService {
return `${this.baseUrl}${path.startsWith('/') ? '' : '/'}${path}`;
}
// // Call on app start, or from guard
// async ensureTokenReady(): Promise<void>{
// if(this.tokenReady$.value) return;
// Call on app start, or from guard
async ensureTokenReady(): Promise<void>{
if(this.tokenReady$.value) return;
// const stored = this.safeGetToken();
const stored = this.safeGetToken();
// // try to restore from storage
// if(stored){
// this.accessTokenSub.next(stored);
// this.tokenReady$.next(true);
// return;
// }
// try to restore from storage
if(stored){
this.accessTokenSub.next(stored);
this.tokenReady$.next(true);
return;
}
// // // Optionally: try a silent refresh on startup to restore session using HttpOnly cookie
// // try {
// // const res = await firstValueFrom(this.refreshToken());
// // this.safeSetToken(res.accessToken);
// // }
// // catch{
// // console.warn('Silent token refresh failed on startup');
// // }
// // finally{
// // this.tokenReady$.next(true);
// // }
// }
// // Optionally: try a silent refresh on startup to restore session using HttpOnly cookie
// try {
// const res = await firstValueFrom(this.refreshToken());
// this.safeSetToken(res.accessToken);
// }
// catch{
// console.warn('Silent token refresh failed on startup');
// }
// finally{
// this.tokenReady$.next(true);
// }
}
get currentToken(): string | null {
return this.safeGetToken();
@@ -123,7 +124,7 @@ export class AuthService {
logout(): Observable<void> {
this.accessToken = null;
this.safeRemoveToken();
this.router.navigate(['/login']);
this.router.navigate(['/admin/login']);
return of();
}
+7 -13
View File
@@ -1,7 +1,13 @@
<div class="verify-wrapper">
<div class="verify-card">
<h2 class="title">🔐 OTP Verification</h2>
@if(!isOtpSent()){
<h2 class="title">🔐 Login</h2>
}
@if(isOtpSent() && !isVerified()){
<h2 class="title">🔐 OTP Verification</h2>
}
<!-- Step 1: Enter Email -->
@if (!isOtpSent()) {
@@ -35,17 +41,5 @@
</button>
</div>
}
<!-- Step 3: Success -->
<!-- @if (isVerified()) {
<div>
<p class="success-msg">{{ message() }}✅</p>
</div>
}
@if (isError()) {
<p class="error-message">{{ message() }}</p>
} -->
</div>
</div>