Passing data from `event.locals` to Frontend
Hey folks, I'm super new to solid/solid start, but I'm trying to implement some authentication and I have my user's session in
event.locals
and its available in Middleware / BE.
But how do I access that event.locals
data in the frontend? Having trouble finding anything online.8 Replies
To be clear, using beta.2
Maybe this is how
Ah that did it! Thanks ❤️
It's important to note that SolidStart's middleware won't intercept client-side nav.
@Atila , what is the implication of that? Does getRequestEvent only give the first event in a potential series?
if you try to protect a route via a middleware, it won't work for soft-navigation (SPA)
Does getRequestEvent only give the first event in a potential series?that's a second case where, at the moment, the won't match assets - so it doesn't fire a million times, no need to filter routes out. But it intercepts every flight between client/server - so if you fire a redirect or something, it will fire multiple times. I think for protecting a route, the best case would be to add the logic in a parent route preload function. so
/protected/*
can redirect if user is not authorizedCan't really wrap my head around it. I'll have to think about that.
Particularly, I like Nuxt's approach, where the developer can define route-specific middleware and then do the protection.
https://nuxt.com/docs/getting-started/routing#route-middleware
I think there's a chance we get there, but I'm not sure how much work is required under the hood to going through middleware on every navigation.