PhilippCh4ts
PhilippCh4ts
SSolidJS
Created by Hussein on 5/21/2024 in #support
how do i redirect on load?
As soon as you add a direct dependency in the route component to a cache point that just threw a redirect, the navigation to that route will comply with the redirect as well.
Gosh, that was it. Everything working as expected now 🥳 Thanks so much for the pointers, that’s great info!
26 replies
SSolidJS
Created by Hussein on 5/21/2024 in #support
how do i redirect on load?
Sorry new to Solid altogether. Where exactly would I check the value of that header? On nativeEvent within the cache fn? Bit puzzled as to what’s happening here, I’ve tried to create a reproduction yesterday and it did in fact work as expected. So I thought maybe it had to do something with my local setup. Anyway, I’m just trying the Stackblitz example again now (not having changed anything) and the same issue is appearing https://stackblitz.com/edit/github-qbrg4x?file=src%2Froutes%2F(admin).tsx Also downloaded this project locally, and can reproduce there too. Edit: Not sure if related, but there is an error showing up in the console when refreshing the /manage-orders page.
Uncaught (in promise) Response {type: 'default', url: '', redirected: false, status: 302, ok: false, …}
Uncaught (in promise) Response {type: 'default', url: '', redirected: false, status: 302, ok: false, …}
26 replies
SSolidJS
Created by Hussein on 5/21/2024 in #support
how do i redirect on load?
Ah, sorry. Didn’t notice while copying the example. I did try both throw and return, neither works
26 replies
SSolidJS
Created by Hussein on 5/21/2024 in #support
how do i redirect on load?
Facing the same issue right now. At least according to the docs, this is supposed to work as confirmed in this thread, right? https://docs.solidjs.com/solid-start/advanced/auth#protected-routes I have a similar implementation for an (admin).tsx route group, see below. It logs null for the user object, but doesn’t redirect. Am I missing something?
const getCurrentUser = cache(function () {
"use server";
const event = getRequestEvent()!;
if (!event.locals.user) {
console.log(event.locals.user);
return redirect("/login");
}
return event.locals.user;
}, "current_user");

export const route = {
load() {
void getCurrentUser();
},
} satisfies RouteDefinition;
const getCurrentUser = cache(function () {
"use server";
const event = getRequestEvent()!;
if (!event.locals.user) {
console.log(event.locals.user);
return redirect("/login");
}
return event.locals.user;
}, "current_user");

export const route = {
load() {
void getCurrentUser();
},
} satisfies RouteDefinition;
26 replies