question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`getSession`'s status is always unauthenticated on server-side in route middlewares

See original GitHub issue

Environment

Nuxi 3.0.0-rc.13 RootDir: /Users/nook/work/tls-interim-front Nuxt project info: (copied to clipboard)


  • Operating System: Darwin
  • Node Version: v18.12.0
  • Nuxt Version: 3.0.0-rc.13
  • Nitro Version: 0.6.1
  • Package Manager: npm@8.19.2
  • Builder: vite
  • User Config: typescript, css, modules, auth, build, googleFonts, runtimeConfig
  • Runtime Modules: @nuxtjs/tailwindcss@6.1.3, @nuxtjs/google-fonts@3.0.0-1, @nuxtjs/svg@0.4.0, @pinia/nuxt@0.4.3, floating-vue/nuxt, @sidebase/nuxt-auth@0.0.1-beta.5
  • Build Modules: -

Reproduction

No response

Describe the bug

Given I am authenticated:

When trying to guard a route, the session is always null (unauthenticated) on server side, but available on client side

definePageMeta({
  middleware: [async () => {
    const { status } = await useSession();
    console.log(status.value); // 'unauthenticated' on server, 'authenticated' on client
    if (status.value === 'authenticated') {
      return true;
    } else {
      console.log('hmm not ok');
      console.log(status.value); // 'unauthenticated' on server
    }
  }],
});

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BracketJohncommented, Nov 17, 2022

Hey @noook and @darwebdb (who I know is tracking this for his blog-post https://darweb.nl/blog/article/user-auth-and-session-management-in-nuxt3-with-sidebase-nuxt-auth-and-strapi-v4-1)

v0.1.0 is out now 🎊 It includes isomorphic useSession which resolves this issue (: Let me know or open a new issue if something comes up.

Use the release as:

npm i -D @sidebase/nuxt-auth@0.1.0
1reaction
BracketJohncommented, Nov 12, 2022

hm, I briefly tried it and it threw some other error. I’ll investigate a bit more (:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel sanctum unauthenticated - Stack Overflow
I am using Laravel sanctum in my project with angular as frontend. Getting unauthenticated from the second api request. Please ...
Read more >
Is NextAuth middleware enough to secure all pages and APIs?
For context, I'm using Google Auth, and export { default } from "next-auth/middleware" to secure pages / APIs. Whenever a user navigates to...
Read more >
ASP.NET Core Middleware | Microsoft Learn
Authentication Middleware (UseAuthentication) attempts to authenticate the user before they're allowed access to secure resources. Authorization ...
Read more >
Securing pages and API routes - NextAuth.js
The methods getSession() and getToken() both return an object if a session is valid and null if a session is invalid or has...
Read more >
Using API route in inertia + laravel always returns ... - Laracasts
I was able to login using inertia form, but if I use auth:sanctum in my API route middleware, it does not work... it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found