1

I have been looking for a good boilerplate on AngularJs with built-in registration and login and I found one, which works pretty well for my needs:

https://github.com/softwaremill/bootzooka/tree/master/ui

However, I cannot make it work because of line 8 in UserSessionService.js (https://github.com/softwaremill/bootzooka/blob/master/ui/app/session/userSessionService.js)

var loggedUserPromise = $http.get('api/users').then(function (response) {...

I edited it in this way: var loggedUserPromise = $http.get('http://www.mybackend.com/login').then(function (response) {...

My server has only two routes, mybackend.com/login which gets username and password and retrieves an apikey, and mybackend.com/getuser which gets the apikey and returns various userdata.

The problem is that var loggedUserPromise = $http.get('http://www.mybackend.com/login').then(function (response) {... always returns a 401 since the params (username and password) are not given.

What could it be the error?

Thank you all! :-)

2 Answers 2

3

You should provide the params...

$http.get('http://www.mybackend.com/login', {username: "username", password: "password"}).then(function (response) {
Sign up to request clarification or add additional context in comments.

1 Comment

I tried, but the loggedUserPromise init is called before the user actually performs the login
1

I solved setting var loggedUserPromise = null; at the beginning and then

    userSessionService.getLoggedUserPromise = function () {
    loggedUserPromise = $http.get("http://mybackend.com/user/getself", {params: {Authorization: sessionStorage.token}}).then(function (response) {
        loggedUser = response.data;
    });
    return loggedUserPromise;
};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.