Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Simple Auth different redirects after authentication

I'm using Ember simple auth in my app and it's working great, but I've run into a scenario that I'm having trouble getting around.

The library lets you specify the route to redirect to after a successful authentication by overriding routeAfterAuthentication: 'index'. This is working fine, however, I'm finding myself in a situation where I want to have two different types of redirects. When a user first logs in, I want them to go to /dashboard, but when they first sign up and authenticate, I want them to go /settings.

I was hoping to be able to do something like this after successfully creating an account, but it's still trying to use the routeAfterAuthentication option for the transition:

var _this = this;

this.set('identification', _this.get('email'));
this.set('password', password);

this.send('authenticate', function() {
  _this.transitionToRoute('settings');
}, function() {});

Is there a way to specify which route to transition to after authenticating on one-off basis? Maybe there's a better way to log someone after they create an account without needing to go through the authenticate() method?

like image 692
Peter Brown Avatar asked Aug 13 '14 19:08

Peter Brown


1 Answers

You can simply override the sessionAuthenticated method in the application route and implement your own logic. Beware though that the default implementation will not always transition to routeAfterAuthentication-- if there's a previously intercepted transition stored in the session, sessionAuthenticated will retry that instead.

like image 88
marcoow Avatar answered Oct 07 '22 02:10

marcoow