username redirect

This commit is contained in:
peintnermax
2024-09-11 13:44:15 +02:00
parent 48291ca6ed
commit 6e01224412
2 changed files with 21 additions and 23 deletions

View File

@@ -76,7 +76,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
params.set("organization", command.organization); params.set("organization", command.organization);
} }
return startIdentityProviderFlow({ const resp = await startIdentityProviderFlow({
idpId: identityProviders[0].id, idpId: identityProviders[0].id,
urls: { urls: {
successUrl: successUrl:
@@ -84,14 +84,14 @@ export async function sendLoginname(command: SendLoginnameCommand) {
failureUrl: failureUrl:
`${host}/idp/${provider}/failure?` + new URLSearchParams(params), `${host}/idp/${provider}/failure?` + new URLSearchParams(params),
}, },
}).then((resp: any) => {
if (resp.authUrl) {
return redirect(resp.authUrl);
}
}); });
} else {
throw Error("Could not find user"); if (resp?.nextStep.case === "authUrl") {
return redirect(resp.nextStep.value);
}
} }
throw Error("Could not find user");
} else if ( } else if (
loginSettings?.allowRegister && loginSettings?.allowRegister &&
loginSettings?.allowUsernamePassword loginSettings?.allowUsernamePassword

View File

@@ -59,7 +59,6 @@ export default function UsernameForm({
authRequestId, authRequestId,
}).catch((error: Error) => { }).catch((error: Error) => {
setError(error.message ?? "An internal error occurred"); setError(error.message ?? "An internal error occurred");
return Promise.reject(error ?? "An internal error occurred");
}); });
setLoading(false); setLoading(false);
@@ -74,30 +73,29 @@ export default function UsernameForm({
const response = await submitLoginName(values, organization); const response = await submitLoginName(values, organization);
if (!response) { if (!response) {
setError("An internal error occurred");
return; return;
} }
if (response?.authMethodTypes && response.authMethodTypes.length === 0) { if (response.authMethodTypes && response.authMethodTypes.length === 0) {
setError( setError(
"User has no available authentication methods. Contact your administrator to setup authentication for the requested user.", "User has no available authentication methods. Contact your administrator to setup authentication for the requested user.",
); );
return; return;
} }
if (response?.authMethodTypes.length == 1) { if (response.authMethodTypes.length == 1) {
const method = response.authMethodTypes[0]; const method = response.authMethodTypes[0];
switch (method) { switch (method) {
case AuthenticationMethodType.PASSWORD: // user has only password as auth method case AuthenticationMethodType.PASSWORD: // user has only password as auth method
const paramsPassword: any = { const paramsPassword: any = {
loginName: response?.factors?.user?.loginName, loginName: response.factors?.user?.loginName,
}; };
// TODO: does this have to be checked in loginSettings.allowDomainDiscovery // TODO: does this have to be checked in loginSettings.allowDomainDiscovery
if (organization || response?.factors?.user?.organizationId) { if (organization || response.factors?.user?.organizationId) {
paramsPassword.organization = paramsPassword.organization =
organization ?? response?.factors?.user?.organizationId; organization ?? response.factors?.user?.organizationId;
} }
if ( if (
@@ -120,9 +118,9 @@ export default function UsernameForm({
paramsPasskey.authRequestId = authRequestId; paramsPasskey.authRequestId = authRequestId;
} }
if (organization || response?.factors?.user?.organizationId) { if (organization || response.factors?.user?.organizationId) {
paramsPasskey.organization = paramsPasskey.organization =
organization ?? response?.factors?.user?.organizationId; organization ?? response.factors?.user?.organizationId;
} }
return router.push( return router.push(
@@ -139,9 +137,9 @@ export default function UsernameForm({
paramsPasskeyDefault.authRequestId = authRequestId; paramsPasskeyDefault.authRequestId = authRequestId;
} }
if (organization || response?.factors?.user?.organizationId) { if (organization || response.factors?.user?.organizationId) {
paramsPasskeyDefault.organization = paramsPasskeyDefault.organization =
organization ?? response?.factors?.user?.organizationId; organization ?? response.factors?.user?.organizationId;
} }
return router.push( return router.push(
@@ -150,7 +148,7 @@ export default function UsernameForm({
} }
} else { } else {
// prefer passkey in favor of other methods // prefer passkey in favor of other methods
if (response?.authMethodTypes.includes(2)) { if (response.authMethodTypes.includes(2)) {
const passkeyParams: any = { const passkeyParams: any = {
loginName: values.loginName, loginName: values.loginName,
altPassword: `${response.authMethodTypes.includes(1)}`, // show alternative password option altPassword: `${response.authMethodTypes.includes(1)}`, // show alternative password option
@@ -160,9 +158,9 @@ export default function UsernameForm({
passkeyParams.authRequestId = authRequestId; passkeyParams.authRequestId = authRequestId;
} }
if (organization || response?.factors?.user?.organizationId) { if (organization || response.factors?.user?.organizationId) {
passkeyParams.organization = passkeyParams.organization =
organization ?? response?.factors?.user?.organizationId; organization ?? response.factors?.user?.organizationId;
} }
return router.push( return router.push(
@@ -180,9 +178,9 @@ export default function UsernameForm({
paramsPasswordDefault.authRequestId = authRequestId; paramsPasswordDefault.authRequestId = authRequestId;
} }
if (organization || response?.factors?.user?.organizationId) { if (organization || response.factors?.user?.organizationId) {
paramsPasswordDefault.organization = paramsPasswordDefault.organization =
organization ?? response?.factors?.user?.organizationId; organization ?? response.factors?.user?.organizationId;
} }
return router.push( return router.push(