nuxt-alt / auth

An alternative module to @nuxtjs/auth
https://nuxt-alt-auth.vercel.app/
MIT License
94 stars 20 forks source link

oAuth2 stuck #85

Closed steklopod closed 6 months ago

steklopod commented 7 months ago

Environment

Nuxt Config

  auth: {
    scopeKey: 'scope',
    globalMiddleware: true,
    // routerStrategy: 'navigateTo',
    strategies: {
      refresh: {
        scheme: 'refresh'
   }
}

Reproduction

https://colaba.online/login?t=0

Снимок экрана 2023-12-04 в 13 56 54

Just press the button and try to login


Describe the bug

I have backend that manages oAuth2.

After success it sets cookies and redirect to main frontend page

Снимок экрана 2023-12-04 в 13 56 17

In latest versions of library if Cookies a set it breaks entire application: redirect will be never finished and node stops working.

Additional context

Desired behaviour

If cookies were set by backend and I was redirected to main page:

This worked earlier. Maybe latest changes with watchLoggedIn causes this 🤷🏻

Denoder commented 7 months ago

Accessing the url itself is loading extremely slow without me interacting, so im uncertain if this pertains to the module at all, and watchLoggedIn was reverted in 3.0.1

steklopod commented 7 months ago

Yes. This is the problem I reported. Loader never ends. Finally there will be timeout error from nginx.

I can't tell you exactly in which version it appeared because I did not tested it a long time. I'll try to investigate and will write later which version causes the problem.

The problem is that it crashes the whole app and I have to manually restart docker container to make it working again.

Also I tried to add second strategy (did not helped):

      cookie: {
        scheme: 'cookie',
        name: 'auth._token.refresh',
}
steklopod commented 7 months ago

It's not possible to rollback to working version (for example 2.6.0) because in library we have latest versions which produces conflicts and fails. Persanally I prefer hard-coded version even without ^

Снимок экрана 2023-12-04 в 15 09 20 Снимок экрана 2023-12-04 в 15 17 03

Looks like removing cookie: { server: true }, causes an error from this release:

https://github.com/nuxt-alt/auth/commit/a9540fbc36b6a4af330046ccead83daa00db576a#r134141891


I can 100% guarantee that it worked in version 2.4.2

Denoder commented 7 months ago

What you're telling me doesn't make sense. I recoupled the cookie scheme back to the local scheme (because I'm trying to maintain the same code structure as the original module unless it really needs a change), the server param was removed because Nuxt 3 was being quirky at the time when working with server/client flow, so I needed to force the difference.

In your first post you are using the refresh scheme which is separate from the cookie scheme and they're both extensions of the local scheme. Google authentication flow needs to be handled by OAuth2.

Any custom modifications you're trying to do should be handled by a custom scheme.

steklopod commented 7 months ago

I always use refresh scheme. It worked before in older versions.

I mentioned cookie scheme to show how I tried to solve the problem by adding second strategy. It did not help.

I don't need Google authentication flow implemented on frontend. I do it on backend. I just reported that earlier the functionality allowed automatic login if user was not loggedIn but token is not empty in cookies.

So let me try to explain it with pseudo-code of auto-login:

onBeforeMount(() => {
  if (!useAuth().loggedIn && cookies.token.isNotEmpty() && cookies.token.isNotExpired()){
    await useAuth().login() // + fetch user
  }
})