Fix user creation
This commit is contained in:
@@ -29,7 +29,7 @@ export class BookService {
|
|||||||
|
|
||||||
loadBooks(): void {
|
loadBooks(): void {
|
||||||
const currentState = this.bookStateSubject.value;
|
const currentState = this.bookStateSubject.value;
|
||||||
if (currentState.loaded) {
|
if (currentState.loaded && this.bookStateSubject.value.books != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.http.get<Book[]>(this.url).pipe(
|
this.http.get<Book[]>(this.url).pipe(
|
||||||
|
|||||||
+7
-5
@@ -67,19 +67,21 @@ export class CreateUserDialogComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.userService.createUser(userData).subscribe({
|
this.userService.createUser(userData).subscribe({
|
||||||
next: response => {
|
next: () => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'User Created',
|
summary: 'User Created',
|
||||||
detail: response.message
|
detail: 'The user has been successfully created.'
|
||||||
});
|
});
|
||||||
this.ref.close(true);
|
this.ref.close(true);
|
||||||
},
|
},
|
||||||
error: err => {
|
error: (err) => {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: 'Error',
|
summary: 'User Creation Failed',
|
||||||
detail: 'Failed to create user: ' + err.error.message
|
detail: err?.error?.message
|
||||||
|
? `Unable to create user: ${err.error.message}`
|
||||||
|
: 'An unexpected error occurred while creating the user. Please try again later.'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!books || books.length === 0">
|
<div *ngIf="!books">
|
||||||
<p-progressSpinner></p-progressSpinner>
|
<p-progressSpinner></p-progressSpinner>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+1
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
.dashboard-scroller-no-books {
|
.dashboard-scroller-no-books {
|
||||||
padding-top: 3rem;
|
padding-top: 3rem;
|
||||||
|
padding-bottom: 3rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class LoginComponent {
|
|||||||
this.authService.login({ username: this.username, password: this.password }).subscribe({
|
this.authService.login({ username: this.username, password: this.password }).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.authService.saveToken(response.token);
|
this.authService.saveToken(response.token);
|
||||||
this.router.navigate(['/all-books']);
|
this.router.navigate(['/dashboard']);
|
||||||
},
|
},
|
||||||
error: () => {
|
error: () => {
|
||||||
this.errorMessage = 'Invalid username or password';
|
this.errorMessage = 'Invalid username or password';
|
||||||
|
|||||||
@@ -82,23 +82,12 @@ export class UserService {
|
|||||||
return this.http.get<User>(`${this.userUrl}/me`);
|
return this.http.get<User>(`${this.userUrl}/me`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserFromAPI(): Observable<User> {
|
|
||||||
const token = localStorage.getItem('token');
|
|
||||||
if (token) {
|
|
||||||
const decoded: JwtPayload & { userId?: string } = jwtDecode(token);
|
|
||||||
if (decoded.userId) {
|
|
||||||
return this.http.get<User>(`${this.userUrl}/${decoded.userId}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return of(null as unknown as User);
|
|
||||||
}
|
|
||||||
|
|
||||||
getLocalUser(): User | null {
|
getLocalUser(): User | null {
|
||||||
return this.userDataSubject.getValue();
|
return this.userDataSubject.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
createUser(userData: Omit<User, 'id'>): Observable<{ message: string }> {
|
createUser(userData: Omit<User, 'id'>): Observable<void> {
|
||||||
return this.http.post<{ message: string }>(this.apiUrl, userData);
|
return this.http.post<void>(this.apiUrl, userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUsers(): Observable<User[]> {
|
getUsers(): Observable<User[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user