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);
}
return startIdentityProviderFlow({
const resp = await startIdentityProviderFlow({
idpId: identityProviders[0].id,
urls: {
successUrl:
@@ -84,14 +84,14 @@ export async function sendLoginname(command: SendLoginnameCommand) {
failureUrl:
`${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 (
loginSettings?.allowRegister &&
loginSettings?.allowUsernamePassword

View File

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