sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.31k stars 164 forks source link

refreshToken used in custom middleware returns null #896

Closed erosRCS closed 2 months ago

erosRCS commented 2 months ago

Environment

Reproduction

  1. Have the following auth configuration

    image
  2. Sign in using signIn composable from useAuth

  3. In a protected page, use a custom auth middleware

    image
  4. Try to get the refresh token using useAuth, and useCookie from Nuxt

    image

Describe the bug

image

refreshToken is returned as null, even thought the cookie does exist, as proved by it existing when using refreshToken with useCookie. This is before its max age is reached. This makes it so that if i want to call the refresh() method from useAuth, it will fail, because a null value will be sent instead of the actual refreshToken. What could be a workaround for this?

Additional context

Im currently trying to define a custom logic to get the access and refresh tokens using this library. For testing, i setted the max age for the access tokens to be just 10 seconds.

For extra context, this problem doesnt happen with the access token, before its 10 seconds mark, which is the expected behaviour as told by the documentation. It only happens with refreshToken for some reason.

Logs

No response

Suniron commented 2 months ago

I have the same problem!

The refresh request, manually triggered, sends refreshToken: null as body which causes a 400 error from my backend API.

In my case I can't use this lib to do my authentication because the refresh feature doesn't work well..

I also tried to use a lighter configuration as possible (I have an issue on this repo with more details) but even in 0.8.x version, it seems to be not really stable šŸ„².

I think it's a problem about an element in the config that must be forced to set (like the default value is not set). I already found a similar problem like this in the past with this lib. But I tried many different configuration šŸ˜„.

I hope we found the mistake because I really like the initiative of this library šŸ˜Š

erosRCS commented 2 months ago

I have the same problem!

The refresh request, manually triggered, sends refreshToken: null as body which causes a 400 error from my backend API.

In my case I can't use this lib to do my authentication because the refresh feature doesn't work well..

I also tried to use a lighter configuration as possible (I have an issue on this repo with more details) but even in 0.8.x version, it seems to be not really stable šŸ„².

I think it's a problem about an element in the config that must be forced to set (like the default value is not set). I already found a similar problem like this in the past with this lib. But I tried many different configuration šŸ˜„.

I hope we found the mistake because I really like the initiative of this library šŸ˜Š

I see, didnt know it was an already old problem. And same as well! I like the library, so hopefully it is an easy fixable bug, or in any case something that can be done with the config files.

phoenix-ru commented 2 months ago

Hi @erosRCS , thank you for a good reproduction! I will take a look into that today