How do I redirect properly?
redirect raises an error,
Error signing in as guest: Response {
status: 302, statusText: '', headers: Headers { location: '/in' }, body: null, bodyUsed: false, ok: false, redirected: false, type: 'default', url: '' }
status: 302, statusText: '', headers: Headers { location: '/in' }, body: null, bodyUsed: false, ok: false, redirected: false, type: 'default', url: '' }
17 Replies
Oh I see. How should I properly do it?
try
Probably
No errors raised but it doesn't redirect to /in. It stays in /login.
Have you checked the
Location
header in the response? Is it /login
or /in
My first suspicion would be that client side protections for /in
are still bouncing the redirect back to /login
.It is /in in the response header.
Do I have to manually get the location from response header and then navigate using useNavigate?
No. But I believe for some reason the logic in your
/in
route doesn't believe that authentication has taken place and immediately navigates to /login
.Currently I do not have a folder called "in". I use FileRoutes. Do I have to create one to make it work? It navigates when I try using useNavigate in client side and it triggers 404 page. But redirect isn't working.
Create a dummy
src/routes/in.tsx
route and see what happens.It raises Hydration mismatch when I manually go to /in route. Also, redirect doesn't work.
It raises Hydration mismatch when I manually go to /in route.For a bare bones static stub? That typically only happens when the HTML is so bad that Chrome starts to "helpfully" correct it. I believe that is a separate problem. The redirect problem suggests that there is something else going on outside of the scope that you have presented so far.
Is it related to the use of FileRoutes? Should I just avoid FileRoutes?
Abandoning FileRoutes is throwing the baby out with bathwater.
- can you create a simple new route (disregarding authentication for now)
- that you can successfully load manually
- and once that works redirect to it
… that's just a basic sanity check to see whether something has gotten seriously bugged at the base.
I will try it!. Thank you so much for your suggestions.
GitHub
[Bug?]: Hydration Error Occurs When Adding New Route · Issue #1286 ...
Duplicates I have searched the existing issues Latest version I have tested the latest version Current behavior 😯 The issue with Solid Start is that whenever I add a new route, it causes a hydratio...
Yes I'm experiencing the same but different. Even if I restart the dev server it does't work.
Now it works when I disable cache inside network tab.
Also, can I ask you a question ?
How can I check session using useSession from vinxi/http inside my entry-server.jsx.
// @refresh reload
import { createHandler, StartServer } from "@solidjs/start/server";
export default createHandler(
() => (
<StartServer
document={({ assets, children, scripts }) => (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<link rel="icon" href="/favicon.ico" />
{assets}
</head>
<body>
<div id="app">{children}</div>
{scripts}
</body>
</html>
)}
/>
),
{ mode: "stream" }
);
May I ask what you are trying to accomplish by accessing it there?
Just trying to preempt the The XY Problem.
Depending on the answer middleware may be called for and/or getCookie to prevent
useSession
from creating a new session by default.Handle Cookie - h3
Use cookies to store data on the client.