Retrieve rails/devise current_user from Backbone

前端 未结 1 767
一整个雨季
一整个雨季 2021-02-04 18:38

I have an app where I manage the sign up/in/out with Rails through Devise.

When I\'m logged in, i\'m redirected to Dashboard#index where Backbone start.

I would

1条回答
  •  感情败类
    2021-02-04 19:21

    (Just beware that only public information should be accesible in the client side)

    For a more elegant solution you can create a UserSession Backbone model and fetch it from the server as normal Backbone model.

    window.App.UserSession = Backbone.Model.extend({
      urlRoot: "/session"
    });
    

    If don't want to make this extra request you can load the model explicitly with data already available in template rendering time:

    window.App.current_user = 
      new window.App.UserSession({
        id:    "#{current_user.id}",
        token: "#{current_user.token}"
      });
    

    0 讨论(0)
提交回复
热议问题