Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$cookies missing after Ajax request #10861

Closed
rogerfar opened this issue Jan 25, 2015 · 2 comments
Closed

$cookies missing after Ajax request #10861

rogerfar opened this issue Jan 25, 2015 · 2 comments

Comments

@rogerfar
Copy link

It's hard to make a plunkr example, but it's easy to reproduce.

As I have a SPA I do authentication serverside through $http (webAPI). I create a $http method which calls a login functions on my backend server, this will set a cookie to authenticate.

After $http is complete I check my cookies:

public get isAuthenticated(): boolean
{
    var cookie1: string = $cookie['.ASPXAUTH'];
    var cookie2: string = $cookie['.ASPXAUTH_USERID'];

    console.log(cookie1, cookie2);
    console.log(document.cookie);

    if (cookie1 && cookie2)
    {
        return true;
    }
    return false;
}

Odd part is that the variables cookie1 and cookie2 are empty, but document.cookie contains the newly set cookies.

After a page refresh all is fine, it seems that $cookie doesn't recognize cookies after they have been set by an ajax call.

@shahata
Copy link
Contributor

shahata commented Jan 25, 2015

Hi @rogier21, this is a duplicate of #7631 and will be resolved in Angular 1.4. In the mean time you can set a timeout of at least 100ms and check the cookies again in order to see the updated cookies after the http response.

@shahata shahata closed this as completed Jan 25, 2015
@rogerfar
Copy link
Author

@shahata Sorry I searched but didn't see this issue! I did see the 1.4 changes but wasn't sure this was considered! Thanks for the swift response.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants