mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-13 13:12:15 +00:00
fix client error
This commit is contained in:
@@ -1,24 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Challenges_Passkey } from "@zitadel/server";
|
||||
import { ChallengeKind, Challenges_Passkey } from "@zitadel/server";
|
||||
import { coerceToArrayBuffer, coerceToBase64Url } from "#/utils/base64";
|
||||
import { Button, ButtonVariants } from "./Button";
|
||||
import Alert from "./Alert";
|
||||
import { Spinner } from "./Spinner";
|
||||
|
||||
type Props = {
|
||||
loginName: string;
|
||||
challenge: Challenges_Passkey;
|
||||
};
|
||||
|
||||
export default function LoginPasskey({ challenge }: Props) {
|
||||
export default function LoginPasskey({ loginName, challenge }: Props) {
|
||||
const [error, setError] = useState<string>("");
|
||||
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
updateSessionForChallenge();
|
||||
}, []);
|
||||
|
||||
async function updateSessionForChallenge() {
|
||||
setLoading(true);
|
||||
const res = await fetch("/api/session", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
loginName,
|
||||
challenges: [1], // request passkey challenge
|
||||
}),
|
||||
});
|
||||
|
||||
setLoading(false);
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to load authentication methods");
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function submitLogin(
|
||||
passkeyId: string,
|
||||
passkeyName: string,
|
||||
@@ -26,7 +50,7 @@ export default function LoginPasskey({ challenge }: Props) {
|
||||
sessionId: string
|
||||
) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/passkeys/verify", {
|
||||
const res = await fetch("/api/passkeys/verify", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -99,13 +123,12 @@ export default function LoginPasskey({ challenge }: Props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="w-full">
|
||||
<div className="w-full">
|
||||
{error && (
|
||||
<div className="py-4">
|
||||
<Alert>{error}</Alert>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-8 flex w-full flex-row items-center">
|
||||
<Button
|
||||
type="button"
|
||||
@@ -127,6 +150,6 @@ export default function LoginPasskey({ challenge }: Props) {
|
||||
continue
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function PasswordForm({ loginName }: Props) {
|
||||
async function submitPassword(values: Inputs) {
|
||||
setError("");
|
||||
setLoading(true);
|
||||
const res = await fetch("/session", {
|
||||
const res = await fetch("/api/session", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -48,7 +48,7 @@ export default function RegisterForm({
|
||||
|
||||
async function submitRegister(values: Inputs) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/registeruser", {
|
||||
const res = await fetch("/api/registeruser", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -36,7 +36,7 @@ export default function RegisterFormWithoutPassword({ legal }: Props) {
|
||||
|
||||
async function submitAndRegister(values: Inputs) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/registeruser", {
|
||||
const res = await fetch("/api/registeruser", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -56,7 +56,7 @@ export default function RegisterFormWithoutPassword({ legal }: Props) {
|
||||
|
||||
async function createSessionWithLoginName(loginName: string) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/session", {
|
||||
const res = await fetch("/api/session", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -29,7 +29,7 @@ export default function RegisterPasskey({ sessionId, isPrompt }: Props) {
|
||||
async function submitRegister() {
|
||||
setError("");
|
||||
setLoading(true);
|
||||
const res = await fetch("/passkeys", {
|
||||
const res = await fetch("/api/passkeys", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -56,7 +56,7 @@ export default function RegisterPasskey({ sessionId, isPrompt }: Props) {
|
||||
sessionId: string
|
||||
) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/passkeys/verify", {
|
||||
const res = await fetch("/api/passkeys/verify", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -17,7 +17,7 @@ export default function SessionItem({
|
||||
|
||||
async function clearSession(id: string) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/session?" + new URLSearchParams({ id }), {
|
||||
const res = await fetch("/api/session?" + new URLSearchParams({ id }), {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -47,7 +47,7 @@ export default function SetPasswordForm({
|
||||
|
||||
async function submitRegister(values: Inputs) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/registeruser", {
|
||||
const res = await fetch("/api/registeruser", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -71,7 +71,7 @@ export default function SetPasswordForm({
|
||||
loginName: string,
|
||||
password: string
|
||||
) {
|
||||
const res = await fetch("/session", {
|
||||
const res = await fetch("/api/session", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -31,7 +31,7 @@ export default function UsernameForm({ loginSettings, loginName }: Props) {
|
||||
|
||||
async function submitLoginName(values: Inputs) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/loginnames", {
|
||||
const res = await fetch("/api/loginname", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -53,25 +53,24 @@ export default function UsernameForm({ loginSettings, loginName }: Props) {
|
||||
console.log(response);
|
||||
if (response.authMethodTypes.length == 1) {
|
||||
const method = response.authMethodTypes[0];
|
||||
console.log(method);
|
||||
// switch (method) {
|
||||
// case AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSWORD:
|
||||
// return router.push(
|
||||
// "/password?" +
|
||||
// new URLSearchParams({ loginName: values.loginName })
|
||||
// );
|
||||
// case AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSKEY:
|
||||
// break;
|
||||
// // return router.push(
|
||||
// // "/passkey/login?" +
|
||||
// // new URLSearchParams({ loginName: values.loginName })
|
||||
// // );
|
||||
// default:
|
||||
// return router.push(
|
||||
// "/password?" +
|
||||
// new URLSearchParams({ loginName: values.loginName })
|
||||
// );
|
||||
// }
|
||||
switch (method) {
|
||||
case 1: //AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSWORD:
|
||||
return router.push(
|
||||
"/password?" +
|
||||
new URLSearchParams({ loginName: values.loginName })
|
||||
);
|
||||
case 2: // AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSKEY
|
||||
return router.push(
|
||||
"/passkey/login?" +
|
||||
new URLSearchParams({ loginName: values.loginName })
|
||||
);
|
||||
default:
|
||||
return router.push(
|
||||
"/password?" +
|
||||
new URLSearchParams({ loginName: values.loginName })
|
||||
);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function VerifyEmailForm({ userId, code, submit }: Props) {
|
||||
|
||||
async function submitCode(values: Inputs) {
|
||||
setLoading(true);
|
||||
const res = await fetch("/verifyemail", {
|
||||
const res = await fetch("/api/verifyemail", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -66,7 +66,7 @@ export default function VerifyEmailForm({ userId, code, submit }: Props) {
|
||||
|
||||
async function resendCode() {
|
||||
setLoading(true);
|
||||
const res = await fetch("/resendverifyemail", {
|
||||
const res = await fetch("/api/resendverifyemail", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
Reference in New Issue
Block a user