Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session information not avaliable on front when using firebase functions #190

Open
ralacerda opened this issue Sep 25, 2024 · 7 comments
Open

Comments

@ralacerda
Copy link

ralacerda commented Sep 25, 2024

Hello. I'm trying to use this module with Nuxt and Firebase but I'm having a few problems.

I'm using firebase function and Google OAuth.
I had to set the NUXT_OAUTH_GOOGLE_REDIRECT_URL, otherwise the redirect url would be the firebase function url.

For the backend part, everything is okay, I get authentication success and I can set the values for the session.
But in my frontend, when using useUserSession() I get an empty session and loggedIn is false. The nuxt-session cookie is present, but the front can't read it.

I already tried turning SSR on and off. Even when SSR is on, the HTML generated by the server doesn't include the user session.

Now, if I call my API and use await getUserSession(event), it works and I can recover the user info.

I'm using version 0.3.9 and I also tried 0.3.4 with no success (I can't go to lower version because I need the redirect_url feature.

Any help debugging the problem will be appreciated.

Copy link
Owner

atinux commented Sep 25, 2024

What happens when you go on /api/_auth/session with your browser once the cookie is set?

@ralacerda
Copy link
Author

I get a 200 response but an empty value.

@ralacerda
Copy link
Author

ralacerda commented Sep 25, 2024

I solved part of the problem. I believe because I misconfigured the OAuth earlier, there was a cookie set for the firebase function url. After clearing that, I'm back to auth not working in any context.

So the problem is most likely that I'm not able to set the user session to the website url. Is there a way to decrypt the cookie so I can check if it's valid?

Copy link
Owner

atinux commented Sep 25, 2024

You can overwrite the cookie domain this way:

export default defineNuxtConfig({
  $production: {
    runtimeConfig: {
      session: {
        cookie: {
          domain: 'example.com'
        }
      }
  }
})

@ralacerda
Copy link
Author

ralacerda commented Sep 25, 2024

Should exemple.com but the hosting url or the firebase function url? I tried both to no avail.
I'm also getting a typescript error that domain is not a property of cookie.

@MasterCarl
Copy link
Contributor

Are you using Safari, by any chance? I spent a few hours debugging an empty response from useUserSession after a successful authentication flow.

Eventually, I noticed that everything did work fine in Chrome. I was able to also get it to work locally in Safari by setting

runtimeConfig: {
    session: {
      cookie: {
        secure: !import.meta.dev,
      },
    },
  },

in nuxt.config.ts.

@birdlavv
Copy link

Looks related to the Safari quirk mentioned in #78 (comment)
Toggling runtimeConfig.session.cookie.secure to false allowed the cookie to be set in my local setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants