I have a login button in my app, when a user clicks on it, the request is sent to the service file, from there firebase looks after the authentication process. My question is if the login is scucessfull and token is set, then i want to use return 'Login Successful' and then print this in the frontend to the client to notify that login is successful. I've tried various ways but couldn't solve this.
Component.ts file
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import { AuthService } from '../auth.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
constructor(
private authService:AuthService
) { }
ngOnInit() {
}
login(form: NgForm) {
const email = form.value.input_emailid;
const password = form.value.input_password;
this.authService.loginUser(email,password);
}
}
My service file(AuthService.ts)
import * as firebase from 'firebase';
import { Router } from '@angular/router';
import { Injectable } from '@angular/core';
@Injectable()
export class AuthService {
constructor(
private router:Router
) {}
token: string;
loginUser(email: string,password: string) {
firebase.auth().signInWithEmailAndPassword(email,password)
.then(
(response) => {
this.router.navigate(['/']);
firebase.auth().currentUser.getIdToken()
.then(
(token: string) => {
this.token = token;
// Want to return the below return statement
return 'Login Successful';
}
)
}
).catch(
error => console.log(error)
)
}