1

I am using this method of redirecting users who are not logged in to another page:

Redirecting not logged-in users with iron-router... Again

The code:

EXCLUDED = ['signin', 'signup', 'forgotPassword', 'terms']
Router.onBeforeAction must_login, except: EXCLUDED
must_login = (pause) ->
  if Meteor.user()
    @setLayout @lookupLayoutTemplate() or 'blank'
  else
    if localStorage.getItem('has_logged_in_before') or Router.current().path is '/signin'
      @setLayout 'signin'
    else
      @setLayout 'signup'
    pause()

For the initial "/" page load, the signin or signup layout is correctly rendered, depending on the browser's localStorage. However, there is a link on the signup page: <a href="/signin">. When it is clicked, the URL changes, but the page stays the same, and onBeforeAction is not rerun. What is the best way to get the page to change?

Community
  • 1
  • 1
Loren
  • 13,903
  • 8
  • 48
  • 79

1 Answers1

2

My guess is that the Router.current().path is still "/" when you check it. It will change after the "onBeforeAction" is done, hence, the if else checks put you in signup again. Try

if localStorage.getItem('has_logged_in_before') or this.route.name is 'signin'

if that won't work console.log the Router.current().path to double check my suspicion, and just try to find out how to get the requested URL.

Let me know how the debugging goes!