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.

Strapi Login logout after page refresh

See original GitHub issue

I am having trouble keeping $strapi.user persistent. I can login fine and cookies and local storage is also set, but upon a page request the user gets logged out straight away.

Is this expected behaviour?

I have tried following:

  strapi: {
    url: "http://localhost:8086",
    key: 'authi_jwt',
    expires: '1d',  
    cookie: {}
  },

To keep the session from expiring …

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:20

github_iconTop GitHub Comments

2reactions
pixelscript-iocommented, Jun 8, 2021

@tobias-srf I fixed this issue by completely clearing the application cache (I was using Google Chrome) and modifying my options object to the following:

strapi: {
  url: 'https://strapi.mydomain.net',
  key: 'authToken',
  expires: '7d',
  cookie: {
    sameSite: true,
    path: '/'
  }
}

Upon inspecting my Network tab when it would redirect me to /login and display I wasn’t logged in, I found some duplicate cookies which I’m assuming is what was causing the issue. I hope this helps!

0reactions
LucaMargadantcommented, Nov 25, 2022

@benjamincanac I think I found the issue. I am using docker and run nuxt and strapi on the same instance. I have a port forwarding set aside for either application. If I tell nuxt to use the port forwarded port for strapi I get the issue.

If I use the internal url via nuxt 127.0.0.1:1337 I get the /user/me GET call and everything is fine and the user stays logged in!

So it looks like it is a partial network issue …

Thank you! For me this worked. Setting an url to the strapi module fixed the issue. While local development the call to strapi was over localhost. Changing strapi’s url in nuxt config to http://127.0.0.1:1337 fixed it.

expires: '30d', url: http://127.0.0.1:1337, cookie: { path: '/', },

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strapi Login logout after page refresh · Issue #138 - GitHub
I am having trouble keeping $strapi.user persistent. I can login fine and cookies and local storage is also set, but upon a page...
Read more >
User Authentication with Next.js and Strapi
NextAuth is an authentication library built for use with Next.js. It's easy, fast, and secure. The code for this tutorial is available on...
Read more >
User Authentication with Strapi and React
If the user already has an account, they'll need a login form to authenticate the application. You'll create a Sign-In page to handle...
Read more >
Registration and Login (Authentication) with Vue.js and Strapi
Fill up the Reset password page input with the following url, http://localhost:8080/resetpassword . Click save, then go back. Getting our Edamam ...
Read more >
How to Implement Authenticated API Requests to Strapi
Next, fill in the needed credentials to successfully log in to the ... Now, on the Settings page, access the Users & Permissions...
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