-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$sessionStorage should return a promise #185
Comments
It does not set any cookie at all. sessionStorage is local to browser and should not be updated in any request. Can you clarify a little what function you would like to have return a promise? |
Sorry, I just edited my first message (I asked for a similar feature for $cookies and I misstyped my last sentence): angular/angular.js#6411 My use case is simple: as soon as the user logs in I get a sid which I want to save in the session/local storage and then I want to immediately call the rest api, putting my sid in the headers. Without a promise $http gets called before the session/local storage gets written, which turns out in a bad authentication because of lack of sid. |
Where you get value to inject into your requests you should be able to use the value straight away: Login Controller / Service would do something like this
and in the $http interceptor would do something like this
As they both now should use the same $sessionStorage they should both have the same value even before the value is synched with window.sessionStorage. Something to that effect? |
I'm currently using the same $sessionStorage ( restService.getDataFromApis() uses restService.resource() ) but the value is not synced.
|
Are you sure your If you get the same resource as you did during the This http://plnkr.co/edit/Qrkl7lUD7tzmyI1OnxtC?p=preview shows that there is no problem setting it in a resource and consuming it right away. I used a run function instead of a controller. |
You're right, my code works. Last time I tried it probably didn't because I was using a separate service for my resource function. Anyway I still think you should add a $promise property to $sessionStorage (like $resource does) to handle such cases. |
You should close this issue. |
Right now if you set $sessionStorage values then call $http immediately, sessionStorage is not updated in the request. if $sessionStorage returns before saving the sessionStorage in the browser then we need callback to execute code that relies on sessionStorage.
It either need to not set the Session Storage asynchronously or provide a call back function.
The text was updated successfully, but these errors were encountered: