Subtletree
Subtletree

Reputation: 3329

Ember.js - Can the root url link to two routes, one for authenticated users and one for guests?

Is it possible for the root path, example.com, to display a landing page(application/index) for not logged in users but a profile page (users/show) for users who are logged in?

Guest user -> example.com -> application/index

Authenticated user -> example.com -> users/show

I know that this goes against Ember's philosophy of the app state being reflected by the url, still, does anyone know if/how this situation is possible?

Cheers!

Upvotes: 1

Views: 200

Answers (1)

Jyoti
Jyoti

Reputation: 94

Yes, You can do it. Firstly, you should check the user logged in or not in "beforeModel" of "application" route. If user is logged in then transits it to "profile" page using "transitionTo" method otherwise transits it to "login" page.

beforeModel: function(transition) {
    var user;
    //put here method to check if user is logged in or not
    if (!user) {
      //if no user then transist to login
      this.transitionTo('login');
    } else {
      //other wise to profile page
      this.transitionTo('profilePage');
    }
}

Upvotes: 1

Related Questions