Closed GuillaumeNury closed 1 year ago
Yes, it's possible to do, but we will need to add the event to the PageServerLoad
object
Something like below:
import type { PageServerLoad } from '@analogjs/router';
export const load = async ({ fetch, req, event }: PageServerLoad) => {
const cookies = parseCookies(event);
console.log('req.url', req.url);
console.log('req.headers', req.headers);
return {
principal: await fetch<{ name: string }>('/api/v1/users/me'),
};
};
OR
import type { PageServerLoad } from '@analogjs/router';
export const load = async ({ fetch, req, cookies, event }: PageServerLoad) => {
console.log('req.url', req.url);
console.log('req.headers', req.headers);
return {
principal: await fetch<{ name: string }>('/api/v1/users/me'),
};
};
Oh! It is that easy 🤦 Thank you for the quick reply and keep the good job on Analog!
Which scope/s are relevant/related to the feature request?
router
Information
Hello!
I use cookies to store authentication token. The
fetch
function inload
does not use original request headers.Given the following code:
It logs:
Is there any ways of using cookies in load function ?
Describe any alternatives/workarounds you're currently using
Make API calls from client.
I would be willing to submit a PR to fix this issue