frontend:add:cookie renewal
This commit is contained in:
@@ -29,8 +29,22 @@ export async function handle({ event, resolve }) {
|
|||||||
|
|
||||||
const userData = await response.json();
|
const userData = await response.json();
|
||||||
|
|
||||||
|
// Check if the server sent a new token
|
||||||
|
const newToken = response.headers.get("Set-Cookie");
|
||||||
|
if (newToken) {
|
||||||
|
const match = newToken.match(/jwt=([^;]+)/);
|
||||||
|
if (match) {
|
||||||
|
event.cookies.set("jwt", match[1], {
|
||||||
|
path: "/",
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === "production", // Secure in production
|
||||||
|
sameSite: "lax",
|
||||||
|
maxAge: 5 * 24 * 60 * 60, // 5 days in seconds
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event.locals.user = userData;
|
event.locals.user = userData;
|
||||||
// event.locals.user = await response.json();
|
|
||||||
if (event.locals.user.date_of_birth) {
|
if (event.locals.user.date_of_birth) {
|
||||||
event.locals.user.date_of_birth =
|
event.locals.user.date_of_birth =
|
||||||
event.locals.user.date_of_birth.split("T")[0];
|
event.locals.user.date_of_birth.split("T")[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user