strongloop / loopback-example-access-control

An example demonstrating LoopBack access control mechanisms.
Other
370 stars 168 forks source link

AccessToken not being sent on subsequent requests after login #26

Closed cnaccio closed 10 years ago

cnaccio commented 10 years ago

I'm getting the following on windows. Everything seemed to be ok except that when I went to write the authentication code I realized that the generated Angular factory was not passing the accesstoken with subsequent requests following the login. When comparing my code against the example application I noticed I'm missing the interceptor code for each endpoint method. I tried setting the public property for AccessToken to true in model-config.json which made the Warning go away, but the login method is still not passing the AccessToken along with subsequent requests. Any help is appreciated!

$ lb-ng ../server/server.js js/lb-services.js Loading LoopBack app "e:\Google Drive\Development\Projects\Tribe Base\Minda\server\server.js" Generating "lbServices" for the API endpoint "/api" Warning: scope User.accessTokens targets class "AccessToken", which is not exposed via remoting. The Angular code for this scope won't be generated. Saving the generated services source to "e:\Google Drive\Development\Projects\Tribe Base\Minda\client\js\lb-services.js"

Here's my login method that was generated "login": { url: urlBase + "/Users/login", method: "POST", },

but I think it should look like this:

"login": { url: urlBase + "/users/login", method: "POST", interceptor: { response: function(response) { var accessToken = response.data; LoopBackAuth.currentUserId = accessToken.userId; LoopBackAuth.accessTokenId = accessToken.id; LoopBackAuth.rememberMe = response.config.params.rememberMe !== false; LoopBackAuth.save(); return response.resource; } } },

cnaccio commented 10 years ago

Figured out the issue. The problem is that I had the old version of loopback installed. I thought I had uninstalled it because I ran the npm uninstall, but I found out that the removal of the angular sdk generator was failing silently due to file path being too long. I used an npm tool called rimraf (npm install rimraf then type rimraf ) to delete the stubborn directory. Reinstalled strongloop, regenerated the Angular service, and now all is working.