Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //COMPONENT
- this.authenticationService.login(this.f.username.value, this.f.password.value)
- .pipe(
- take(1)
- ).subscribe({
- next:() => {
- this.user.next(this.authenticationService.currentUserValue);
- this.isLoggedIn = this.authenticationService.isLoggedIn();
- },
- error:error => {
- console.error(error);
- this.errorsService.sendError(error);
- this.errorsService.registerError(error);
- }
- }
- );
- //SERVICE
- login(username, password) {
- let params = new HttpParams()
- .set('username', username)
- .set('password', password);
- let options = { headers: this.headers, params: params };
- // http.get() ritorna un observable quindi la funzione ritorna l'observable di http.get()
- // e nel componente mi sottoscrivo all' observable
- return this.http.get<any>(serverUrl + 'login', options)
- .pipe(
- map(data => {
- this.setSession(data)
- this.currentUserSubject.next(data.user)
- }),
- retry(3)
- );
- }
Add Comment
Please, Sign In to add comment