S
SolidJS14mo ago
avant

Where to protect SolidStart routes?

I tried layouts, but it loads data only once per page if I'm right, so if user gets logged out it doesn't react I tried middleware like in here https://start.solidjs.com/advanced/middleware, but it didn't re-load either, so am I doing something wrong (I'm not the sharpest tool) or is there a better way?
1 Reply
Martnart
Martnart14mo ago
I'm assuming you're using routeData to handle data fetching. You can provide a key which will trigger a re-execution.
export function routeData() {
return createRouteData(async (key) => {
if (!key) redirect() // or do whatever
return fetchDataWith(key)
},
{ key: () => someReactiveValue }
)}
export function routeData() {
return createRouteData(async (key) => {
if (!key) redirect() // or do whatever
return fetchDataWith(key)
},
{ key: () => someReactiveValue }
)}
https://start.solidjs.com/api/createRouteData#fetching-data-with-a-key I hope this helps