0

I am having some trouble getting the logged in status from the below function. I can set the loggedIn status with currentUser.setProfile(username, token), which works.

But when i then try to get the isLoggedIn afterwards, i can't seem to get it.

console.log(currentUser) return the 2 functions, setProfile and getProfile. But getProfile is just an empty function. I have tried currentUser.getProfile.isLoggedIn among others, but they all just return undefined.

What am i doing wrong?

Function:

(function () {
    "use strict";

    angular
        .module("myApp")
        .factory("currentUser",
                  currentUser)

    function currentUser() {
        var profile = {
            isLoggedIn: false,
            username: "",
            token: ""
        };

        var setProfile = function (username, token) {
            profile.username = username;
            profile.token = token;
            profile.isLoggedIn = true;
        };

        var getProfile = function () {
            return profile;
        }

        return {
            setProfile: setProfile,
            getProfile: getProfile
        }
    }
})();
1
  • 1
    Try currentUser.getProfile().isLoggedIn? Commented Feb 22, 2016 at 7:13

1 Answer 1

1

Because getProfile is a function, you should call it like

currentUser.getProfile().isLoggedIn
Sign up to request clarification or add additional context in comments.

Comments

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.