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.

why Server side getServerSession return null when refresh the page useFetch call the api

See original GitHub issue
// file: ~/pages/get
<template>
    <div>
    {{ user }}
    </div>
</template>

<script setup>
  //  fetch the user
 
  const { data: user } = await useFetch('/api/carrier/get')
</script>

// file: ~/server/api/get.ts
import { getServerSession } from '#auth'
export default eventHandler(async (event) => {
  const session = await getServerSession(event)

  if (!session) {
    return { status: 'unauthenticated!' }
  }
  return { status: 'authenticated!' }
})

Additional information

It return the session when using the nuxtlink go to the page but after refresh the page it would return null. why ?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BracketJohncommented, Dec 23, 2022

No worries (: I’ve also learned from this issue and opened #124 to clarify this on the getServerSession docs page. It’s easy to miss if it’s only on the getToken page and a common enough gotcha!

1reaction
nathanjcollinscommented, Dec 23, 2022

@BracketJohn awesome that works, thank you! Apologies, I did try looking for something like that in the docs, but apparently I didn’t look hard enough!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt 3 SSR: useFetch() returning null on page refresh
When $fetch fails server-side, it throws an error and tries again on client-side. This is what I'd expect. However, useFetch and useAsyncData ...
Read more >
`useFetch` data return null with mismatching client ... - GitHub
I am developing a locally based self-hosted certificate. If I use the url address on our production API for useFetch , everything works...
Read more >
Data Fetching: getServerSideProps - Next.js
Pages using getServerSideProps will be server side rendered at request time and only be ... That API route is then called directly from...
Read more >
useFetch
Need to fetch some data? Try this one out. It's an isomorphic fetch hook. That means it works with SSR (server side rendering)....
Read more >
useFetch: React custom hook for Fetch API with Suspense ...
There is no documentation about Concurrent Mode yet. As far as I understand, what we need to care is that a) the render...
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