mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 10:25:58 +00:00
login component
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { getSession, server } from "#/lib/zitadel";
|
import { getSession, server } from "#/lib/zitadel";
|
||||||
import Alert, { AlertType } from "#/ui/Alert";
|
import Alert, { AlertType } from "#/ui/Alert";
|
||||||
|
import LoginPasskey from "#/ui/LoginPasskey";
|
||||||
import RegisterPasskey from "#/ui/RegisterPasskey";
|
import RegisterPasskey from "#/ui/RegisterPasskey";
|
||||||
import UserAvatar from "#/ui/UserAvatar";
|
import UserAvatar from "#/ui/UserAvatar";
|
||||||
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
|
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
|
||||||
@@ -50,9 +51,7 @@ export default async function Page({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{sessionFactors?.id && (
|
{sessionFactors?.id && <LoginPasskey sessionId={sessionFactors.id} />}
|
||||||
<LoginPasskey sessionId={sessionFactors.id} isPrompt={!!prompt} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,37 +56,6 @@ export default function LoginPasskey({ sessionId }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function submitLoginAndContinue(value: Inputs): Promise<boolean | void> {
|
function submitLoginAndContinue(value: Inputs): Promise<boolean | void> {
|
||||||
return submitLogin().then((resp: LoginPasskeyResponse) => {
|
|
||||||
const passkeyId = resp.passkeyId;
|
|
||||||
|
|
||||||
if (
|
|
||||||
resp.publicKeyCredentialCreationOptions &&
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey
|
|
||||||
) {
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey.challenge =
|
|
||||||
coerceToArrayBuffer(
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey.challenge,
|
|
||||||
"challenge"
|
|
||||||
);
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey.user.id =
|
|
||||||
coerceToArrayBuffer(
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey.user.id,
|
|
||||||
"challenge"
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey.excludeCredentials
|
|
||||||
) {
|
|
||||||
resp.publicKeyCredentialCreationOptions.publicKey.excludeCredentials.map(
|
|
||||||
(cred: any) => {
|
|
||||||
cred.id = coerceToArrayBuffer(
|
|
||||||
cred.id as string,
|
|
||||||
"excludeCredentials.id"
|
|
||||||
);
|
|
||||||
return cred;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
navigator.credentials
|
navigator.credentials
|
||||||
.get({
|
.get({
|
||||||
publicKey: resp.publicKeyCredentialCreationOptions,
|
publicKey: resp.publicKeyCredentialCreationOptions,
|
||||||
@@ -120,7 +89,7 @@ export default function LoginPasskey({ sessionId }: Props) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return submitVerify(passkeyId, "", data, sessionId);
|
return submitLogin(passkeyId, "", data, sessionId);
|
||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setError("An error on retrieving passkey");
|
setError("An error on retrieving passkey");
|
||||||
@@ -136,7 +105,6 @@ export default function LoginPasskey({ sessionId }: Props) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// return router.push(`/accounts`);
|
// return router.push(`/accounts`);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { errors } = formState;
|
const { errors } = formState;
|
||||||
@@ -174,7 +142,7 @@ export default function LoginPasskey({ sessionId }: Props) {
|
|||||||
className="self-end"
|
className="self-end"
|
||||||
variant={ButtonVariants.Primary}
|
variant={ButtonVariants.Primary}
|
||||||
disabled={loading || !formState.isValid}
|
disabled={loading || !formState.isValid}
|
||||||
onClick={handleSubmit(submitRegisterAndContinue)}
|
onClick={handleSubmit(submitLoginAndContinue)}
|
||||||
>
|
>
|
||||||
{loading && <Spinner className="h-5 w-5 mr-2" />}
|
{loading && <Spinner className="h-5 w-5 mr-2" />}
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user