cornflourblue / mean-angular2-registration-login-example

MEAN Stack with Angular 2 User Registration and Login Example
http://jasonwatmore.com/post/2017/02/22/mean-with-angular-2-user-registration-and-login-example-tutorial
MIT License
121 stars 113 forks source link

Show login failed error #4

Open shahzadthathal opened 7 years ago

shahzadthathal commented 7 years ago

Hi, Great tutorial thanks for it.

I have an issue to display the error if user email or password is incorrect. Please let me know how should I fix it?

in user authentication service I'm getting this response from the server, how can I pass this response to alert service, I see you are passing response when the user logged in successfully but not if user put invalid email.

Response {_body: "{"error":"Invalid email."}", status: 200, ok: true, statusText: "OK", headers: Headers…}
 login(email: string, password: string) {
        return this.http.post(this.config.apiUrl + '/api/users/login', { email: email, password: password })
            .map((response: Response) => {
                console.log('resonse',response);
                // login successful if there's a jwt token in the response
                let user = response.json();
                if (user && user.token) {
                    // store user details and jwt token in local storage to keep user logged in between page refreshes
                    localStorage.setItem('currentUser', JSON.stringify(user));
                }
            });
    }
SunnyPatel29 commented 7 years ago

Hi I am also facing problem with the login as well as registration
image

mylastore commented 6 years ago

@SunnyPatel29 @shahzadthathal you need to run both server and client both npm start