Skip to content

Commit 21d7254

Browse files
committed
fix(auth): support homer-core v11 wrapped auth response
Unwrap { data } envelope and guard user.user before assigning username.
1 parent 8364b86 commit 21d7254

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/app/services/authentication.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,24 @@ export class AuthenticationService {
8181
}
8282
login(username: string, password: string, type: string) {
8383
return this.http.post<any>(`${environment.apiUrl}/auth`, { username, password, type })
84-
.pipe(map(user => {
84+
.pipe(map(response => {
85+
// homer-core v11+ wraps response in {data: {...}, success: true}
86+
const user = response?.data || response;
8587
// login successful if there's a jwt token in the response
86-
if (user?.token ) {
87-
user.user.username = username;
88+
if (user?.token) {
89+
if (user.user) {
90+
user.user.username = username;
91+
}
8892
// store user details and jwt token in local storage to keep user logged in between page refreshes
8993
setStorage(ConstValue.CURRENT_USER, user);
9094
this.currentUserSubject.next(user);
9195
setTimeout(() => {
9296
this.getUserSettingTimeZone(user, username);
9397
});
9498
} else {
95-
user.user.username = username;
99+
if (user?.user) {
100+
user.user.username = username;
101+
}
96102
this.currentUserSubject.next(user);
97103
setTimeout(() => {
98104
this.getUserSettingTimeZone(user, username);

0 commit comments

Comments
 (0)