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

Value is missing on SSR

Open paulvonber opened this issue 1 year ago • 6 comments

Can you please clarify why I can't get loggedIn.value on SSR is this intended behaviour?

here is how my code looks like:

  const { $auth } = useNuxtApp()
  const { user, loggedIn } = $auth

  if (import.meta.server) {
    console.log(`🆘 ~ SERVER loggedIn:`, loggedIn)
    console.log(`🆘 ~ SERVER loggedIn:`, loggedIn.value)
  }

  if (import.meta.client) {
    console.log(`🆘 ~ CLIENT loggedIn:`, loggedIn)
    console.log(`🆘 ~ CLIENT loggedIn:`, loggedIn.value)
  }

And here is the result: SSR: image

CLIENT: image

paulvonber avatar Jun 22 '24 17:06 paulvonber

@paulvonber Can you create a reproduce repo on codesandbox or stackblitz? It seem something's wrong with your code, I'm testing on local but the SSR works just fine.

The component

Screenshot 2024-06-24 at 08 39 11

The debug log on server side

Screenshot 2024-06-24 at 08 38 51

Screenshot 2024-06-24 at 08 38 35

The SSR content

Screenshot 2024-06-24 at 08 38 15

trandaison avatar Jun 24 '24 01:06 trandaison

@trandaison I'll try to find a time to create repro as this is a bit of things to do. But would you try out to get the value within the middleware as I have problem there in the page/component everything works correctly for me as well.

paulvonber avatar Jun 24 '24 05:06 paulvonber

@paulvonber The same result.

Screenshot 2024-06-24 at 21 04 52 Screenshot 2024-06-24 at 21 03 20 Screenshot 2024-06-24 at 21 02 20

Did you set auth.middleware.global = false in the nuxt.config.ts file?

trandaison avatar Jun 24 '24 14:06 trandaison

I do have auth.middleware.global = true not sure if that anyhow clashes, but I also try to use it in middleware_name.global.js so globally as well.

paulvonber avatar Jun 24 '24 14:06 paulvonber

I got it. Your middleware is a global one, and it has a higher order than the auth middleware, so it executes before the auth middleware where I put the logic to determine the login session.

I will fix in the next release. Thanks for the support!

trandaison avatar Jun 27 '24 23:06 trandaison

@paulvonber This issue is related to an nuxt issue here: https://github.com/nuxt/nuxt/issues/27932 It was fixed however it will be release in the next major version (v4.0.0), after v4 is released, this issue will be fix on nuxt-3-auth.

trandaison avatar Aug 13 '24 11:08 trandaison