API Authentication not working

Hey, its me again.

Okay so i followed the sapphire docs and made the authenticated precondition be

export const authenticated = () =>
    createFunctionPrecondition(
        (request: ApiRequest) => Boolean(request.auth?.token),
        (_request: ApiRequest, response: ApiResponse) => response.error(HttpCodes.Unauthorized)
    );





and i make the api call to refresh/fetch a user from the endpoint users/@me but i get
{ error: "Cannot read properties of null (reading 'id')" }
when i log the response data returned here so that means
auth
is null? i have
credentials: 'include'
in the request tho
Solution
@Oreo ™ Try using the
fetch
on the
event
object from the params. It's SvelteKit's special fetch that can include credentials and such.
import type { Handle } from '@sveltejs/kit';

export const handle: Handle = async ({ event, resolve }) => {
    const { fetch } = event;

    await fetch('https://example.com', {
        method: 'GET'
    });

    return resolve(event);
};
Was this page helpful?