0

This is silly question. I am calling rest service from Angular like that:

UserService.GetByUsername(username)
    .then(function (user) {
        if (user !== null && user.password === password) {

                        response = { success: true };
...

I can see from the debugger that there really is a user object with proper value from DB:

{
firstName: "Suba",
lastName: "Superi",
lastUpdated: "2015-06-02T18:14:56+03:00",
nickName: "",
password: "super",
userId: 2,
username: "super"
}

Question

Why this (user.password) is undefined: if (user !== null && user.password === password). Is there something in my notation or how can I check if password from DB is the same than user inputed in form? How can I get that password from JSON returned from rest, json parse maybe? I just started AngularJS and to implement authentication and login, so don't bother even password are plain text etc :) This is just annoying me. User is an object, I think that this is the reason, cause I assume that it is type of user?

5
  • Are you sure that user.password is undefined? If anything password would be undefined. I don't see where password is defined. Commented Jun 10, 2015 at 20:48
  • 2
    Post your service code too. Commented Jun 10, 2015 at 20:49
  • password is from form and user is from db. I checked it with chrome debugger and user is not null and there is correct object, but user.password is still undefined as a whole, password is getting correct value as well. Commented Jun 10, 2015 at 21:02
  • You've made a (probably small) mistake somewhere. You aren't giving enough information to help. Commented Jun 10, 2015 at 21:35
  • Thanks @Andy Gaskell as well for helping me. It was a really small and silly mistake and basically it was just because of naming response as a user and it confused me. user.data.password or response.data.password Commented Jun 10, 2015 at 22:20

1 Answer 1

2

Are you sure that you are getting the "user" object and not the response object in the then() ?

UserService.GetByUsername(username)
    .then(function (response) {
        if (response && response.data && response.data.password === password) {
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I got a response object, NOT a user. That was it. I just changed this: UserService.GetByUsername(username) .then(function (user) { if (user !== null && user.data.password === password) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.