refactor: address loading review findings (#18)
This commit is contained in:
1 parent
ec3319494b
commit
0f68a91c5d
26 files changed
+607
-364
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable, inject, signal } from '@angular/core';
|
||||
import { computed, Injectable, inject, signal } from '@angular/core';
|
||||
|
||||
interface UserResponse {
|
||||
authenticated: boolean;
|
||||
@@ -13,7 +13,7 @@ export type SessionStatus = 'checking' | 'authenticated' | 'anonymous' | 'error'
|
||||
export class SessionService {
|
||||
private readonly http = inject(HttpClient);
|
||||
readonly status = signal<SessionStatus>('checking');
|
||||
readonly isLoggedIn = signal(false);
|
||||
readonly isLoggedIn = computed(() => this.status() === 'authenticated');
|
||||
readonly username = signal('');
|
||||
readonly email = signal('');
|
||||
|
||||
@@ -21,13 +21,11 @@ export class SessionService {
|
||||
this.status.set('checking');
|
||||
this.http.get<UserResponse>('/api/user').subscribe({
|
||||
next: (user) => {
|
||||
this.isLoggedIn.set(user.authenticated);
|
||||
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