From 20f1ea48493052ee61b2d47009eb645986e85615 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 13 Aug 2023 09:46:43 +0300 Subject: [PATCH] THROW_ON_AUTH_ERROR feature flag --- app/modules/auth/routes.server.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/modules/auth/routes.server.ts b/app/modules/auth/routes.server.ts index ad6c495c7..9c49cd931 100644 --- a/app/modules/auth/routes.server.ts +++ b/app/modules/auth/routes.server.ts @@ -10,6 +10,8 @@ import { import { authSessionStorage } from "./session.server"; import { getUserId } from "./user.server"; +const throwOnAuthErrors = process.env["THROW_ON_AUTH_ERROR"] === "true"; + export const callbackLoader: LoaderFunction = async ({ request }) => { const url = new URL(request.url); if (url.searchParams.get("error") === "access_denied") { @@ -23,7 +25,8 @@ export const callbackLoader: LoaderFunction = async ({ request }) => { await authenticator.authenticate(DISCORD_AUTH_KEY, request, { successRedirect: "/", - failureRedirect: authErrorUrl("unknown"), + failureRedirect: throwOnAuthErrors ? undefined : authErrorUrl("unknown"), + throwOnError: throwOnAuthErrors, }); throw new Response("Unknown authentication state", { status: 500 });