seanlee10
seanlee10

Reputation: 29

Can Angular.js read a server session attribute?

I'm trying to build an auth process using angular.js

basically what I want to achieve is to set a session timeout after a certain period of idle.

I also want to expire the current session when a user logs in from another machine.

so in either case 1) idle timeout, 2) duplicate user log in, the server invalidates the token which leads to a 401 Unauthorized error to a user.

and I'm using a $httpProvider interceptor to catch that 401 error and display appropriate message to the user.

The problem is that I want to be able to tell whether the 401 came from 1) idle timeout or 2) duplicate user log in.

I put a flag in the backend as a session attribute but I can't retrieve the session attribute from the angular frontend.

so, my question is,

1) if it's possible for a javascript to read a session attribute 2) if not, what are the alternative ways to tell whether a status code 410 comes from 1) idle timeout or 2) duplicate user log in.

Thank you in advance!

Upvotes: 0

Views: 1020

Answers (1)

plasma147
plasma147

Reputation: 2211

No, angular runs on the client so it has no access to server side state.

That said, you can return information in the entity of the 401 response to distinguish between the 2 errors.

Upvotes: 1

Related Questions