David Dahan
David Dahan

Reputation: 11192

HowTo: AngularJS Basic Auth + cookie to a REST API server?

I'd like to handle Basic Auth with AngularJS the right way. I'm pretty sure the answer is somewhere on SO, but I didn't find it. It seems that everyone has particular need about authentication and I'm confused. Note that I have no particular knowledge about authentication so sorry for dummy questions.

The case

What works for now

Login works now this way:

It works as expected.

What's wrong with this

The only problem with that system, is that when the smartphone application (ie. the angularJS/Cordova app) is closed, everything is lost and the user needs to log in again.

How could I fix it? Thanks a lot.

Upvotes: 0

Views: 2206

Answers (1)

David Dahan
David Dahan

Reputation: 11192

Actually, it seems that cookies (even if the expiration date if set in the future) are deleted by Cordova when the application is closed, and there is now way to work around this.

However, using LocalStorage instead of cookies solves the problem perfectly. It's basically the same way to use than cookies since it's a key->value store. It's even cleaner.

This article is a good introduction to localStorage.

Upvotes: 1

Related Questions