15 Replies
it crashes the whole server
redirect
is for use within cache
/action
, try extracting that async function into a cache
and calling it in load
when i
return redirect
it doesn't do anythingda heck, can you show your code now?
actually wait
i got a different problem
this is what i'm getting
yea that's odd, i'm not sure
I wonder whether the issue is that the redirect happens on the server side.
Given that this
is a request to
/server_
that thrown response would have to be serialized and sent in a wrapper response to get back to the client (I think Ryan demonstrated that that actually works).
However on client side the router would be staring at the unwrapped redirect response? I guess that could be made to work …
OK… that error happens as soon as you make the load function async
by extension redirects won't work.
I think the idea is to only warm the cache in the load and then act on it later in the route component.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?
In your case it may actually start to work if you
i do this to protect
/
but that doesn't work with redirecting from /login
to /
if you're already logged inAh, sorry. Didn’t notice while copying the example. I did try both
throw
and return
, neither worksThe point of interest then is what is in the response from the server. For this to work
/login
needs to be in the Location
header. Two paths:
- if it's not there, why isn't it
- if it's there, why isn't the router navigating
In your OP the issue was when you are redirecting.
From what I could tell the async load
tried to access the response header when it was already too late.
So is it perhaps possible that you are redirect
ing (on the server side) outside of where the server's response can be touched or something else is modifying the Location
header later?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.
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.
Where exactly would I check the value of that header?In this particular case I was talking about looking at the response to in the network tab of the developer tools. That request will happen as soon as you hover over the
manage-order
link because of the getCurrentUser()
you put in the route component's load function.
Once you click on the request, you get access to the Headers
tab which lists the request and response headers.
The raw version of the response headers look like:
Notice the Location: /
—that is the result of your redirect
.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!