diff --git a/apps/login/src/components/sign-in-with-idp.tsx b/apps/login/src/components/sign-in-with-idp.tsx index 555b90feee3..e94ba8364bc 100644 --- a/apps/login/src/components/sign-in-with-idp.tsx +++ b/apps/login/src/components/sign-in-with-idp.tsx @@ -64,6 +64,11 @@ export function SignInWithIdp({ setLoading(false); }); + if (response && "error" in response && response?.error) { + setError(response.error); + return; + } + if (response && "redirect" in response && response?.redirect) { return router.push(response.redirect); } diff --git a/apps/login/src/lib/server/idp.ts b/apps/login/src/lib/server/idp.ts index 2077e1697ff..ebb755987e7 100644 --- a/apps/login/src/lib/server/idp.ts +++ b/apps/login/src/lib/server/idp.ts @@ -12,11 +12,15 @@ export type StartIDPFlowCommand = { export async function startIDPFlow(command: StartIDPFlowCommand) { const host = (await headers()).get("host"); + if (!host) { + return { error: "Could not get host" }; + } + return startIdentityProviderFlow({ idpId: command.idpId, urls: { - successUrl: `${host}${command.successUrl}`, - failureUrl: `${host}${command.failureUrl}`, + successUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.successUrl}`, + failureUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.failureUrl}`, }, }).then((response) => { if (