Peter Brown
Peter Brown

Reputation: 51707

Redirect user to the same page after logging out

Sometimes I would like to be able to have a user log out, but stay on the page they were already on.

I'm using invalidateSession to log the user out, but this reloads the application and takes them to my application's root URL - the login page. In some cases, this is not the behavior I want, and I would instead like to have the user stay on the page they're on, but show the "logged out" version of that page.

Is there a way to log a user out and either a) not reload the application, or b) specify which page they should be redirected to after log out?

I've tried transitioning to another route, but there doesn't seem to be a way to do this after the session is invalidated (it's not a promise).

Upvotes: 2

Views: 1240

Answers (1)

flylib
flylib

Reputation: 1148

in your application route you can override this by doing something like

import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {

actions: {
  sessionInvalidationSucceeded: function(){
   var currentRoute = this.controllerFor('application').get('currentRouteName');
   this.transitionTo(currentRoute); // or whatever route you want
  },
  sessionInvalidationFailed: function(error){
    console.log(error);
    var currentRoute = this.controllerFor('application').get('currentRouteName');
    this.transitionTo(currentRoute); // or whatever route you want
  }
}
});

the default behavior of sessionInvalidationSucceeded is do basically a window reload and you can override this by overriding the method

Upvotes: 1

Related Questions