show already setupped methods

This commit is contained in:
peintnermax
2024-04-23 10:50:58 +02:00
parent 44435ad0e5
commit 827af38220
6 changed files with 277 additions and 369 deletions

View File

@@ -2,6 +2,8 @@ import {
getBrandingSettings,
getLoginSettings,
getSession,
getUserByID,
listAuthenticationMethodTypes,
server,
} from "#/lib/zitadel";
import Alert from "#/ui/Alert";
@@ -34,8 +36,15 @@ export default async function Page({
organization
);
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session) {
return response.session;
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id
).then((methods) => {
return {
factors: response.session?.factors,
authMethods: methods.authMethodTypes ?? [],
};
});
}
});
}
@@ -43,8 +52,15 @@ export default async function Page({
async function loadSessionById(sessionId: string, organization?: string) {
const recent = await getSessionCookieById(sessionId, organization);
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session) {
return response.session;
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id
).then((methods) => {
return {
factors: response.session?.factors,
authMethods: methods.authMethodTypes ?? [],
};
});
}
});
}
@@ -67,19 +83,18 @@ export default async function Page({
></UserAvatar>
)}
{!sessionFactors && <div className="py-4"></div>}
{!(loginName || sessionId) && (
<Alert>Provide your active session as loginName param</Alert>
)}
{loginSettings ? (
{loginSettings && sessionFactors ? (
<ChooseSecondFactorToSetup
loginName={loginName}
sessionId={sessionId}
authRequestId={authRequestId}
organization={organization}
loginSettings={loginSettings}
userMethods={sessionFactors.authMethods ?? []}
></ChooseSecondFactorToSetup>
) : (
<Alert>No second factors available to setup.</Alert>

View File

@@ -1,6 +1,7 @@
import { getBrandingSettings, getLoginSettings, server } from "#/lib/zitadel";
import DynamicTheme from "#/ui/DynamicTheme";
import LoginOTP from "#/ui/LoginOTP";
import LoginPasskey from "#/ui/LoginPasskey";
import VerifyU2F from "#/ui/VerifyU2F";
export default async function Page({
@@ -22,12 +23,13 @@ export default async function Page({
<p className="ztdl-p">Verify your account with your device.</p>
<VerifyU2F
<LoginPasskey
loginName={loginName}
sessionId={sessionId}
authRequestId={authRequestId}
organization={organization}
></VerifyU2F>
altPassword={false}
></LoginPasskey>
</div>
</DynamicTheme>
);