I’m sure there is a simple answer, but I am struggling a bit. Using iron:router, and accounts. The goal is to always have a user routed to the same route, once he/she logs in. I have the “welcome” page down for when a user is unauthenticated, but once a user is first logged-in I want to invalidate any previous routes that might be pending (IE. this.next()).
I have tried to do a check on “first-login” status and added a call to a route in the “this.next()” else block, but in some cases get a meteor error that says the expected route was not rendered.
1st for unauthenticated users, they are directed to the “welcomeButLogin” landing page, which works well.
Secondly, I have users that might have used the application, is currently on a page, IE. ‘postList’, and then sign out. If they subsequently log back in, the this.next() behavior will reload the ‘postList’ page in this example. What I would like to accomplish is, that regardless what page the previously logged-in user signed out of the application, they always be directed to a single pre-specified route (IE. ‘dashboard’) as a landing page once they log back in.
Folks, I am making progress, but I am certain that there is a better, more elegant way to accomplish this functionality. As before, I want users to “always” be directed to a welcome page once they log into the application, even if they were previously signed-out at a different page. What trips me up is the “this.next()” requirement for iron Router’s onBeforeAction.
Briefly a scenario:
User navigates to the application and is prompted with a “Welcome but please sign-in/up” page.
User signs in, and the router directs the user to a “welcome to the application” page
User navigates through the application to “pageOne” and then decides to sign out, and is again presented with the “Welcome but please sign-in/up” page being rendered. (However, the URL still reads http://xxx.xxx.xxx.xxx/pageOne)
User signs-in again, where now the application should instead of rendering the “pageOne” page, which is the behavior of this.next(), be presented with the “welcome to the application” page.
I was able to get to this functionality with the code below:
Edit: I wasn’t able to set ‘firstLogin’ on the Accounts.onLogin callback (Session object doesn’t exist yet) so I just put it in the else block for users not logged in.
Thank you for suggested changes solarc. I have made these changes, and the functionality works as expected, but however I am still getting the:
Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?
warning message. It seems that the “onBeforeAction” will always require the “this.next()” method be called (also in the iron:router guide). I think I might be looking for some method that can be called in order to “abandon” the current route (on which the onBeforeAction is called), and move to the newly specified one, in our case “/”.
per your suggested code. I don’t quite understand how this changes the routing specific behavior, since I interpreted that “{except” [‘blah’]}" would mean all routes since I did not have a “blah” route. I’ll investigate further, but for now it works as expected, and I am not getting the warning message.