import { Component } from '@angular/core';
-import { Router } from '@angular/router-deprecated';
+import { Router } from '@angular/router';
-import { AuthService, AuthStatus, User } from '../shared';
+import { AuthService } from '../shared';
@Component({
selector: 'my-login',
})
export class LoginComponent {
+ error: string = null;
+
constructor(
private authService: AuthService,
private router: Router
login(username: string, password: string) {
this.authService.login(username, password).subscribe(
result => {
- const user = new User(username, result);
- user.save();
-
- this.authService.setStatus(AuthStatus.LoggedIn);
+ this.error = null;
- this.router.navigate(['VideosList']);
+ this.router.navigate(['/videos/list']);
},
error => {
+ console.error(error);
+
if (error.error === 'invalid_grant') {
- alert('Credentials are invalid.');
+ this.error = 'Credentials are invalid.';
} else {
- alert(`${error.error}: ${error.error_description}`);
+ this.error = `${error.error}: ${error.error_description}`;
}
}
);