Skip to content

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

@skpnoes

Description

@skpnoes
// 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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions