Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.get('_session.user') is undefined #3

Closed
icaliman opened this issue May 28, 2014 · 4 comments
Closed

model.get('_session.user') is undefined #3

icaliman opened this issue May 28, 2014 · 4 comments

Comments

@icaliman
Copy link

I have this route:

app.get '/', (page, model, params, next) ->
  user = model.get '_session.user'
  # ...

When page is rendered on the client side user is undefined.

@vmakhaev can you help me with this issue?

@vmakhaev
Copy link
Member

Yes, I know about this problem.
User is subscribed to '_session.user' only on server and it works for one page apps. If you change page on client, user is not subscribed again, you should do it yourself for the moment. Something like this (just add it before other routes):

app.get '*', (page, model, params, next) ->
    if model.get '_session.loggedIn'
      userId = model.get '_session.userId'
      $user = model.at "users.#{userId}"
      model.subscribe $user, ->
        model.ref '_session.user', $user
        next()
    else
      next()

@icaliman
Copy link
Author

@vmakhaev thanks for answer, and thank you for this nice module!

@vmakhaev
Copy link
Member

@icaliman you are welcome!

@mattbrun
Copy link
Contributor

mattbrun commented Jan 8, 2015

Just for the records, if you use the derby-router package the new way to achieve this is using a route module as explained here.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants