mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 05:12:20 +00:00
username redirect
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user