1

I have a try / catch in my handle function in hooks.server.ts file where I'm validating a JWT.

If the JWT validates, I set the event.locals and resolve the event, but if it fails I redirect to a login page. The issue now I think is that Sveltekit cannot set the types of my locals.

Is there any easy way to solve this? I'm currently getting errors in my load functions because of this.

I want to use properties in my event.locals object but typescript is complaining that the property does not exist on type "Locals"

I've tried a basic example where I set event.local.hello = "world" but this doesnt work either.

EDIT: The types for the locals value need to be manually set in the app.d.ts file in your SvelteKit project. This is documented here: https://kit.svelte.dev/docs/types#app

justintimeza
  • 1,064
  • 4
  • 8

0 Answers0