Skip to content

Commit d794101

Browse files
ericallam0ski
andauthored
fix(webapp): fix broken MFA by only committing one auth session set-cookie call (#3104)
Co-authored-by: Oskar Otwinowski <oskar.otwinowski@gmail.com>
1 parent f325638 commit d794101

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

apps/webapp/app/routes/login.mfa/route.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { InputOTP, InputOTPGroup, InputOTPSlot } from "~/components/primitives/I
2020
import { Paragraph } from "~/components/primitives/Paragraph";
2121
import { Spinner } from "~/components/primitives/Spinner";
2222
import { authenticator } from "~/services/auth.server";
23-
import { commitSession, getUserSession, sessionStorage } from "~/services/sessionStorage.server";
23+
import { commitSession, getUserSession } from "~/services/sessionStorage.server";
2424
import { getSession as getMessageSession } from "~/models/message.server";
2525
import { MultiFactorAuthenticationService } from "~/services/mfa/multiFactorAuthentication.server";
2626
import { redirectWithErrorMessage, redirectBackWithErrorMessage } from "~/models/message.server";
@@ -152,17 +152,16 @@ export async function action({ request }: ActionFunctionArgs) {
152152
}
153153

154154
async function completeLogin(request: Request, session: Session, userId: string) {
155-
// Create a new authenticated session
156-
const authSession = await sessionStorage.getSession(request.headers.get("Cookie"));
157-
authSession.set(authenticator.sessionKey, { userId });
155+
// Set the auth key on the same session object to avoid conflicting Set-Cookie headers
156+
// (both authSession and session share the same __session cookie name)
157+
session.set(authenticator.sessionKey, { userId });
158158

159159
// Get the redirect URL and clean up pending MFA data
160160
const redirectTo = session.get("pending-mfa-redirect-to") ?? "/";
161161
session.unset("pending-mfa-user-id");
162162
session.unset("pending-mfa-redirect-to");
163163

164164
const headers = new Headers();
165-
headers.append("Set-Cookie", await sessionStorage.commitSession(authSession));
166165
headers.append("Set-Cookie", await commitSession(session));
167166

168167
await trackAndClearReferralSource(request, userId, headers);

0 commit comments

Comments
 (0)