I'm using an external api which redirects the user to the following page after logging in:
http://localhost:5173/redirect?token={JWT token}
The JWT is added by the external api.
I managed to store the JWT in a cookie with the following route:
// routes/redirect.tsx
import { useSearchParams, createCookieSessionStorage } from "solid-start";
import { createServerData$, redirect } from "solid-start/server";
export const storage = createCookieSessionStorage({
cookie: {
name: "token",
httpOnly: true,
sameSite: "lax",
path: "/",
maxAge: 60 * 60 * 24 * 14,
secure: true,
},
});
export default function routeData() {
return createServerData$(async () => {
const [query] = useSearchParams<{token: string}>();
const session = await storage.getSession();
session.set("token", query.token);
return redirect("/profile", {
headers: {
"Set-Cookie": await storage.commitSession(session),
},
});
});
}
as described here: https://start.solidjs.com/advanced/session
To me it does not seem like the correct solution for my case because the session is already stored on the external api server. (now also on my server?)
What is the correct way of storing this cookie (or any cookie) and how do I access the cookie on a page?