nuxt-auth-utils icon indicating copy to clipboard operation
nuxt-auth-utils copied to clipboard

Setting user session doesn't work on mobile devices

Open michalwinter opened this issue 1 year ago • 7 comments

Hello, in my login API event handler, I am using the setUserSession() function to set the information of the logged in user. image

On my local machine (my PC), the session setting works without any problems. But on my mobile devices, which access the dev website throught the local network, it doesnt work at all.

I have tried catching any errors as you can see, but after the session is set using the setUserSession() and after I try to fetch the session in the middleware, it comes out as not logged in. image

Not sure if this problem is with my devices or if it has to do something with Nuxt being hosted on a different machine and being accessed through local network, but thanks for any kind of help.

Cheers, Michal.

michalwinter avatar Oct 25 '24 13:10 michalwinter

I have tried getting the session back right after setting the session in the server api file and it returns the correct set object. But back on the client side, the fetch returns nothing.

image

But what I have found out, is that the sessions output differ on mobile and on PC. (Top is mobile device, under it is log from PC device request)

image

michalwinter avatar Oct 25 '24 13:10 michalwinter

One issue could be that your mobile does not send the cookie is not on https connexion

try deploying your project to see if the error persists

atinux avatar Oct 27 '24 13:10 atinux

@atinux is there a way to disable secure? I just plugged this framework into a local network only app and I have the same issue when I deploy it to my home lab .. just found this question.

shurth avatar Oct 30 '24 14:10 shurth

Can this be fixed on testing

tinegaCollins avatar Nov 27 '24 18:11 tinegaCollins

Any solution for this issue. This is implementation blocker for me. It has nothing to do in my understanding. Clients within same network gets empty session responce. if you use localhost for viewing page, all is fine.

BITRU avatar Jan 29 '25 12:01 BITRU

It doesn't work even in the same machine using the Network, it's because local dev env is not secure.

Image

carlos-duran avatar May 08 '25 05:05 carlos-duran

If sessions don’t persist on the Network in dev. I fixed it by adding this to disable secure in nuxt.config.ts (✅ dev only):

runtimeConfig: {
    session: {
      name: 'nuxt-session',
      password: process.env.NUXT_SESSION_PASSWORD || "",
      cookie: {
        secure: false,
        sameSite: 'lax',
        httpOnly: true,
        domain: undefined
      }
    }
  }

⚠️ In production, use secure: true + a real domain.

oussamalkd avatar Sep 09 '25 11:09 oussamalkd