protocol for host, error handling

This commit is contained in:
Max Peintner
2024-12-03 10:54:07 +01:00
parent 69d8381804
commit c2295760dc
2 changed files with 11 additions and 2 deletions

View File

@@ -64,6 +64,11 @@ export function SignInWithIdp({
setLoading(false); setLoading(false);
}); });
if (response && "error" in response && response?.error) {
setError(response.error);
return;
}
if (response && "redirect" in response && response?.redirect) { if (response && "redirect" in response && response?.redirect) {
return router.push(response.redirect); return router.push(response.redirect);
} }

View File

@@ -12,11 +12,15 @@ export type StartIDPFlowCommand = {
export async function startIDPFlow(command: StartIDPFlowCommand) { export async function startIDPFlow(command: StartIDPFlowCommand) {
const host = (await headers()).get("host"); const host = (await headers()).get("host");
if (!host) {
return { error: "Could not get host" };
}
return startIdentityProviderFlow({ return startIdentityProviderFlow({
idpId: command.idpId, idpId: command.idpId,
urls: { urls: {
successUrl: `${host}${command.successUrl}`, successUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.successUrl}`,
failureUrl: `${host}${command.failureUrl}`, failureUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.failureUrl}`,
}, },
}).then((response) => { }).then((response) => {
if ( if (