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:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thegetToken
page and a common enough gotcha!@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!