Nuxtjs get User.current() server side Parse SDK

Hi guys, please help me solve one problem with Parse SDK
I use ‘parse/node’ for server side and ‘parse’ for client side

  1. I want to get Parse.User.current() on
    nuxtServerInit({ commit }, { req }) { const user = this.$Parse.User.current() ; ... },
    but user === null also after login. i think it is the correct behavior because server dosen’t know about localStorage and store in not set on page refresh
  2. On page reload.The serve has not access to $parse.Usere.current(). And the middleware redirect every time to start page.
  3. asyncData cannot fetch dates from DB if without current user

In the documentation it is written JavaScript Developers Guide | Parse

Please note that this functionality is disabled by default on Node.js environments (such as React Native) to discourage stateful usages on server-side configurations. To bypass this behavior on this particular use case, call once Parse.User.enableUnsafeCurrentUser() right before using any cached-user related functionalities.

I use Parse.User.enableUnsafeCurrentUser() function before user login.

My code Repository
How do I get User.current () on the server?

I think to set a cookie with user id to fetch user server side. But is that a good approach?

Thanks very much!

Yes. That’s the way to go. You will have to send the session token from client to server using a cookie.

1 Like