This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/plugins/api.ts | |
| import { appendResponseHeader } from 'h3'; | |
| import { parseCookie, parseSetCookie, stringifyCookie } from 'cookie'; | |
| export default defineNuxtPlugin(() => { | |
| const event = import.meta.server ? useRequestEvent() : undefined; | |
| // During SSR, we parse the initial browser cookies. During the request lifecycle, | |
| // we update this object with new cookies from backend responses (e.g. after a token refresh). | |
| const cookies = import.meta.server && event ? parseCookie(event.node.req.headers.cookie ?? '') : {}; |