question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

User Data Lost on Refresh

See original GitHub issue

Hello!

I am running a Nuxt project with Strapi backend, and am updating it to work with this new module. However, I am having issues managing the authentication flow.

The Issue

Logging in and navigating the app works fine, but since Nuxt is rendered server side, if I refresh the page the data stored in $strapi.user is lost.

Is there a correct way to implement this module to avoid this happening? Previous to using this module, I used a VueX store and cookies, and then used nuxtServerInit() to fetch the data from the Cookie and commit it to the user. WOndering if there is a way to avoid doing this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
gulipadcommented, Aug 17, 2020

Thanks @sandiprb! Looks like this solves the issue! Thanks!

0reactions
merijnponzocommented, Nov 27, 2020

Hi, I noticed that $strapi.login does populate and return a full user object (if your user has relations, most of the will be returned as full objects as well)

But $strapi.fetchUser doesn’t Within your dashboard.vue / or whatever route to the user dashboard you can add your wanted object to create a full strapi user object again

 middleware: 'isAuthenticated',
  async asyncData({ $typy, $strapi }) {
    // by default $strapi.user is not populated, so add the kennel as an object
    if ($typy($strapi, 'user.house').isNumber) {
      const house = await $strapi.$houses.findOne($strapi.user.house)
      // add a reactive house object
      const user = { ...$strapi.user }
      user.house = kennel
      $strapi.setUser(user)
Read more comments on GitHub >

github_iconTop Results From Across the Web

system refresh and my lost data files - Microsoft Community
I got the computer back, but all my data files seem missing / disappeared. I AM very careful NOT to choose RESET, but...
Read more >
User Data Lost on Refresh #31 - nuxt-modules/strapi - GitHub
Hello! I am running a Nuxt project with Strapi backend, and am updating it to work with this new module. However, I am...
Read more >
Losing Context Data on Page Refresh - Stack Overflow
Then I call the recipe ID down from context in my RecipeInfoPage.js file to make the necessary API call, this is the page...
Read more >
How to Save State to LocalStorage & Persist on Refresh with ...
To do this we'll use localStorage, a native API in browsers, that let's us store data. When we run our localStorage functions, we...
Read more >
How To Reload Current Page Without Losing Any Form Data ...
The easiest way to reload current page without losing any form data in Javascript is to use the localStorage .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found