how to redirect from form actions
I want to redirect to the index page from signin form action on successful with
Any insight would be helpful
My current code doesn't redirect
14 Replies
hmm this should work
should this work? it doesn't
the signin one is weird it works if I remove everything b/w getRquestevent and use server even if it get pasts all the early returns, because the cookie is set correctly it just doesn't redirect
also this only redirects if it's wrapped in cache, is that intended? if yes is this documented somewhere?
thanks for any help, really appreciate it π
This wonβt work as the redirect helper only works if the function is wrapped in cache/action
Got it, couldn't find the documentation saying that
I see the examples have cache, I still think it could help if its added to the text as well, is the docs repo accepting PRs?
Thank you for all the help Brendon π
yeah it's open to PRs
https://github.com/solidjs/solid-docs-next/issues/820
apparently someone is already on it
GitHub
[Request]: When to use useNavigate vs redirect Β· Issue #820 Β· solid...
What is this request related to? Request π Suggested https://docs.solidjs.com/solid-router/reference/data-apis/response-helpers#redirect And maybe in here as well: https://docs.solidjs.com/solid-ro...
figured out why the original redirect wasn't working, my auth guard would redirect back to sign in, must have something to do with the order in which cookies are updated and requests being made
Is there a way to make sure my layout load runs after the cookies are set?
removing cache from
getUser
fixed it
getUser
was used in the layout guardah btw
cache
functions should be kept at the top level, not declared inline like thiscan I ask the reason?
the idea is that you declare the data fetcher once and then reuse it
so you'd reuse that cached function anywhere you need the user
got it, I think in this case the cache function would still be only called once
so no matter where you request user data that redirect will happen
and you can call it both in the preload + use it in your markup
you mean in the getUser function? if I use cache there it doesn't redirect properly
or invalidate properly I should say
removing it fixed the issue
I understand that means getUsers is called on every navigation but I think thats whats supposed to happen with auth guards
i'd argue otherwise but whatever works