Comments (6)
Start a new pull request in StackBlitz Codeflow.
from nuxt.js.
You would need to set the cookie returned by useFetch on the HTML response. This isn't done automatically right now, but we might consider doing it for useFetch.
from nuxt.js.
@danielroe thanks for the answer!
But that doesn't work for me either. I created a composable fetchWithCookie and used it in my code. The sessionId is different every time.
<script setup>
const event = useRequestEvent();
const { data } = await useAsyncData(() => fetchWithCookie(event, '/api/test'));
</script>
<template>
<div>
<p>
If you simply refresh the page, there will be a new session every time.
</p>
<pre>{{ data }}</pre>
<p>
But if you go straight to endpoint:
<a href="/api/test">/api/test</a>, the session id will be remain
permanent. Just what I need!
</p>
</div>
</template>
from nuxt.js.
I solved my issue via middleware. And it’s strange, it doesn’t work in the endpoint, but works in the middleware. How can it be?
/server/middleware/session.ts
export default defineEventHandler(async (event) => {
console.log('middleware', {
sessionId: event.context.sessionsId,
cookie: getCookie(event, 'seesion-id-test-2'),
})
if (event.context.sessionsId) {
return
}
const session = await getSession(event, {
password: '80d42cfb-1cd2-462c-8f17-e3237d9027e9',
name: 'seesion-id-test-2',
cookie: {
maxAge: 3600,
path: '/',
sameSite: true,
},
})
event.context.sessionsId = session.id
})
from nuxt.js.
every stranger how it work, with axios onRequest and onResponse great fine, or am I using it wrong?
from nuxt.js.
@leofredy
can you provide an example?
from nuxt.js.
Related Issues (20)
- What is the best practice for useId and getting rid of these hydration errors.
- Development server keeps trying to reach localhost:24678 which doesn't exist HOT 17
- useCookie navigateTo new page hydration HOT 6
- SSR Context Lost HOT 5
- [nuxt] `useId` might not work correctly with components that have `inheritAttrs: false`. HOT 3
- When running npm run generate, the script path is incorrect. HOT 2
- Server component cannot be used with kebab-case HOT 1
- 404 error after running `npx nuxi generate` with `app.baseURL` set. HOT 6
- Fail to alter the nuxt config via module HOT 5
- Nuxt 3.12 - ssr: false, nuxt generate - 404 on routes after page refresh HOT 3
- Nuxt2 cssnano version is too high HOT 4
- feat(kit): add `prepend` option to `addRouteMiddleware` HOT 3
- Bug Report: SyntaxError in @vue/devtools-core Module HOT 3
- `noScripts` improvements HOT 1
- navigateTo in middleware will double encode url on SSR HOT 5
- When loading the real machine on the mobile terminal in the production environment for the first time, _nuxt/builds/meta/xx.json failed to detch appears. After refreshing the browser, it is normal. Why HOT 4
- definePageMeta doesn't work/ gets ignored HOT 2
- `nuxtRoute` doesn't work at all in Server Components. Hydration error in Universal Components nested in Server Components HOT 1
- Component fails on initial page load, but works after HMR
- V4 - Cannot read properties of undefined (reading 'bind') - @nuxt/kit HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.js.