feat: add comprehensive loading feedback (#18)
This commit is contained in:
1 parent
45de0cebcc
commit
ec3319494b
47 files changed
+1753
-406
No files matched your search
@@ -7,22 +7,28 @@ interface UserResponse {
|
||||
email?: string;
|
||||
}
|
||||
|
||||
export type SessionStatus = 'checking' | 'authenticated' | 'anonymous' | 'error';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SessionService {
|
||||
private readonly http = inject(HttpClient);
|
||||
readonly status = signal<SessionStatus>('checking');
|
||||
readonly isLoggedIn = signal(false);
|
||||
readonly username = signal('');
|
||||
readonly email = signal('');
|
||||
|
||||
refresh(): void {
|
||||
this.status.set('checking');
|
||||
this.http.get<UserResponse>('/api/user').subscribe({
|
||||
next: (user) => {
|
||||
this.isLoggedIn.set(user.authenticated);
|
||||
this.username.set(user.authenticated ? (user.username || 'User') : '');
|
||||
this.email.set(user.authenticated ? (user.email || '') : '');
|
||||
this.status.set(user.authenticated ? 'authenticated' : 'anonymous');
|
||||
this.username.set(user.authenticated ? user.username || 'User' : '');
|
||||
this.email.set(user.authenticated ? user.email || '' : '');
|
||||
},
|
||||
error: () => {
|
||||
this.isLoggedIn.set(false);
|
||||
this.status.set('error');
|
||||
this.username.set('');
|
||||
this.email.set('');
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user