Ember-simple-auth: Handling an expired server session

Created on 1 Nov 2017  路  5Comments  路  Source: simplabs/ember-simple-auth

I was hoping someone might be able to provide on guidance on the best way to handle an expired server session?
I was hoping to have the following behavior, but haven't been able to make it work yet:

  1. User is navigates to a particular route
  2. Model hook's API call returns a 401
  3. User is redirected to the login screen
  4. Upon successful reauth, user is redirected the previously attemptedTransition

Any help is appreciated. Let me know if there is anything I can clarify. Thanks!

question

All 5 comments

  1. to 3. is already how ESA works out of the box. As there is not necessarily a transition available when the app receives a 401 response, 4. isn't super straight forward to implement but you should be able to override the DataAdapterMixin's ensureResponseAuthorized method and maybe store the current route somewhere and then also override the ApplicationRouteMixin's sessionAuthenticated and redirect to the previously stored route if present.

@marcoow, thanks for the response!
Yes, 1-3 are definitely working for me, I was just having trouble figuring out how to accomplish 4. I'll attempt what you suggest and update. Thanks again!!!

@marcoow, any recommendations on what would be an acceptable replacement for the behavior in application-route-mixin.sessionInvalidated()? Seems like I would need to change window.location.replace(Configuration.baseURL), since I don't think I'd be able to store the transition otherwise (please let me know if I'm missing something here). Thanks!

Yes, I think you'd want something like this:

if (!testing) {
  if (/* identify your special case here */) {
    // if you're in FastBoot, call transitionTo, otherwise window.location.replace
  } if (this.get('_isFastBoot')) {
    this.transitionTo(Configuration.baseURL);
  } else {
    window.location.replace(Configuration.baseURL);
  }
}

Thanks for your help @marcoow!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

szsoppa picture szsoppa  路  6Comments

wukongrita picture wukongrita  路  5Comments

dmathieu picture dmathieu  路  7Comments

arenoir picture arenoir  路  4Comments

Sinled picture Sinled  路  5Comments