Skip to content

Explicitly Set-Cookie ("remember" behavior) #255

Answered by dvnrsn
dvnrsn asked this question in Q&A
Discussion options

You must be logged in to vote

Ok this works (edited because I had forgotten the very important session.set(authenticator.sessionKey, user);

const user = await authenticator.authenticate("user-pass", request, {
    failureRedirect: "/join",
    context: { formData },
  });

const session = await sessionStorage.getSession(
  request.headers.get("Cookie"),
);
session.set(authenticator.sessionKey, user);
const headers = new Headers({
  "Set-Cookie": await sessionStorage.commitSession(session, {
    maxAge: remember ? 30 * 24 * 60 * 60 : undefined,
  }),
});
return redirect(redirectTo, { headers });

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dvnrsn
Comment options

Answer selected by dvnrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants