Skip to content

Commit 750ac84

Browse files
committed
Handles user response
1 parent b082e5d commit 750ac84

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/app/authentication/service/authentication.service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { environment } from '@environments/environment';
55
import { BehaviorSubject, Observable } from 'rxjs';
66
import { map } from 'rxjs/operators';
77
import { User } from '../model/user';
8+
import { Response } from '@app/api/model/response';
89

910
@Injectable({
1011
providedIn: 'root'
@@ -27,9 +28,8 @@ export class AuthenticationService {
2728
}
2829

2930
login(username: string, password: string) {
30-
return this.http.post<any>(`${environment.apiUrl}/login`, { username, password })
31+
return this.http.post<User>(`${environment.apiUrl}/login`, { username, password })
3132
.pipe(map(user => {
32-
// store user details and basic auth credentials in local storage to keep user logged in between page refreshes
3333
user.authdata = window.btoa(username + ':' + password);
3434
localStorage.setItem('user', JSON.stringify(user));
3535
this.userSubject.next(user);
@@ -38,10 +38,14 @@ export class AuthenticationService {
3838
}
3939

4040
logout() {
41-
// remove user from local storage to log user out
41+
// remove user from local storage and set current user to null
4242
localStorage.removeItem('user');
4343
this.userSubject.next(new User());
4444
this.router.navigate(['/login']);
4545
}
4646

47+
register(user: User) {
48+
return this.http.post(`${environment.apiUrl}/users/register`, user);
49+
}
50+
4751
}

0 commit comments

Comments
 (0)