как отправить сообщение в оконную функцию оповещения после вызова вызова с сообщением - PullRequest
0 голосов
/ 24 октября 2019

Я хочу отправить сообщение своим пользователям, как только они будут отклонены либо по электронной почте не найден, либо по неверному паролю, но я не могу отправить его в всплывающее окно, но вижу его на консоли.

Я получаю сообщение {code: "Unauthorized", message: "Authentication Failed"} в браузере, но хочу отправить его в окно .alert, используя Angular 6 в качестве внешнего интерфейса, и NodeJ, используя Angular 6 в качестве внешнего интерфейса, и NodeJs

const bcrypt = require('bcryptjs');
    const mongoose = require('mongoose');
    const ClearAdmin = mongoose.model('ClearAdmin');

    exports.authenticate = (email, password) => {
      return new Promise(async (resolve, reject) => {
        try {
          //get clearadmin by email and
          const clearadmin = await ClearAdmin.findOne({ email });
          //Match the pasword
          bcrypt.compare(password, clearadmin.password, (err, isMatch) => {
            if (err)
              throw err;
            if (isMatch) {
              resolve(clearadmin);
            }
            else {
              //pass didint match
              reject('Authentication Failed');

            }
          });
        }
        catch (err) {
          //Email not found
          reject('Authentication Failed');
        }
      });
    }```



    *Here is my login.component.ts*

    ```import { Component, OnInit } from '@angular/core';
    import { AuthService } from 'src/app/auth.service';
    import { Router, ActivatedRoute } from '@angular/router';


    @Component({
      selector: 'app-login',
      templateUrl: './login.component.html',
      styleUrls: ['./login.component.css']
    })
    export class LoginComponent implements OnInit {

      constructor(private Auth: AuthService,private router: Router,private activatedRouter: ActivatedRoute) { }

      ngOnInit() {

      }
      loginUser(event)
      {
        event.preventDefault()
        const target = event.target
        const email= target.querySelector('#email').value
        const password = target.querySelector('#password').value

         this.Auth.getUserDetails(email,password).subscribe(data =>{
           if(this.Auth.isAuthenticated(),data.token)
           {
            localStorage.setItem('token',data.token);
            this.router.navigate(['/'], { relativeTo: this.activatedRouter })
             return true;
           }

           else
           {
             window.alert(data.message);
           }
         });
         console.log(email,password)
      }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...