Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active December 28, 2021 22:18
Show Gist options
  • Save NyaGarcia/95e7be2a61090ac15f7a92ad3505e729 to your computer and use it in GitHub Desktop.
Save NyaGarcia/95e7be2a61090ac15f7a92ad3505e729 to your computer and use it in GitHub Desktop.
Adding a login method
import { Component, OnInit } from '@angular/core';
import { AuthService } from 'src/app/core/services/auth.service';
import { LoginData } from 'src/app/core/interfaces/login-data.interface';
import { Router } from '@angular/router';
@Component({
selector: 'app-login-page',
templateUrl: './login-page.component.html',
styleUrls: ['./login-page.component.css'],
})
export class LoginPageComponent implements OnInit {
constructor(
private readonly authService: AuthService,
private readonly router: Router
) {}
ngOnInit(): void {}
login(loginData: LoginData) {
this.authService
.login(loginData)
.then(() => this.router.navigate(['/dashboard']))
.catch((e) => console.log(e.message));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment