mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 06:42:59 +00:00
server route
This commit is contained in:
20
apps/login/app/registeruser/route.ts
Normal file
20
apps/login/app/registeruser/route.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { addHumanUser, server } from "#/lib/zitadel";
|
||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
const body = await request.json();
|
||||||
|
console.log(body);
|
||||||
|
if (body) {
|
||||||
|
const { email, password, firstName, lastName } = body;
|
||||||
|
|
||||||
|
const userId = await addHumanUser(server, {
|
||||||
|
email: email,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
password: password,
|
||||||
|
});
|
||||||
|
return NextResponse.json({ userId });
|
||||||
|
} else {
|
||||||
|
return NextResponse.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,20 +63,22 @@ export function getPasswordComplexityPolicy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type AddHumanUserData = {
|
export type AddHumanUserData = {
|
||||||
displayName: string;
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
export function addHumanUser(
|
export function addHumanUser(
|
||||||
server: ZitadelServer,
|
server: ZitadelServer,
|
||||||
{ email, displayName, password }: AddHumanUserData
|
{ email, firstName, lastName, password }: AddHumanUserData
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const mgmt = getManagement(server);
|
const mgmt = getManagement(server);
|
||||||
return mgmt
|
return mgmt
|
||||||
.addHumanUser(
|
.addHumanUser(
|
||||||
{
|
{
|
||||||
email: { email, isEmailVerified: false },
|
email: { email, isEmailVerified: false },
|
||||||
profile: { displayName },
|
userName: email,
|
||||||
|
profile: { firstName, lastName },
|
||||||
initialPassword: password,
|
initialPassword: password,
|
||||||
},
|
},
|
||||||
{ metadata: orgMetadata(process.env.ZITADEL_ORG_ID ?? "") }
|
{ metadata: orgMetadata(process.env.ZITADEL_ORG_ID ?? "") }
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const check = (
|
|||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
strokeWidth={1.5}
|
strokeWidth={1.5}
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
className="w-6 h-6 las la-check text-state-success-light-color dark:text-state-success-dark-color mr-2 text-lg"
|
className="w-6 h-6 las la-check text-green-500 dark:text-green-500 mr-2 text-lg"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round"
|
strokeLinecap="round"
|
||||||
@@ -58,13 +58,6 @@ export default function PasswordComplexity({
|
|||||||
const hasUppercase = upperCaseValidator(password);
|
const hasUppercase = upperCaseValidator(password);
|
||||||
const hasLowercase = lowerCaseValidator(password);
|
const hasLowercase = lowerCaseValidator(password);
|
||||||
|
|
||||||
const policyIsValid =
|
|
||||||
(passwordComplexityPolicy.hasLowercase ? hasLowercase : true) &&
|
|
||||||
(passwordComplexityPolicy.hasNumber ? hasNumber : true) &&
|
|
||||||
(passwordComplexityPolicy.hasUppercase ? hasUppercase : true) &&
|
|
||||||
(passwordComplexityPolicy.hasSymbol ? hasSymbol : true) &&
|
|
||||||
hasMinLength;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mb-4 grid grid-cols-2 gap-x-8 gap-y-2">
|
<div className="mb-4 grid grid-cols-2 gap-x-8 gap-y-2">
|
||||||
<div className="flex flex-row items-center">
|
<div className="flex flex-row items-center">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { PasswordComplexityPolicy, PrivacyPolicy } from "@zitadel/server";
|
import { PasswordComplexityPolicy, PrivacyPolicy } from "@zitadel/server";
|
||||||
import PasswordComplexity from "./PasswordComplexity";
|
import PasswordComplexity from "./PasswordComplexity";
|
||||||
import { use, useState } from "react";
|
import { useState } from "react";
|
||||||
import { Button, ButtonVariants } from "./Button";
|
import { Button, ButtonVariants } from "./Button";
|
||||||
import { TextInput } from "./Input";
|
import { TextInput } from "./Input";
|
||||||
import { PrivacyPolicyCheckboxes } from "./PrivacyPolicyCheckboxes";
|
import { PrivacyPolicyCheckboxes } from "./PrivacyPolicyCheckboxes";
|
||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
symbolValidator,
|
symbolValidator,
|
||||||
upperCaseValidator,
|
upperCaseValidator,
|
||||||
} from "#/utils/validators";
|
} from "#/utils/validators";
|
||||||
import { addHumanUser, server } from "#/lib/zitadel";
|
|
||||||
|
|
||||||
type Inputs =
|
type Inputs =
|
||||||
| {
|
| {
|
||||||
@@ -30,18 +29,6 @@ type Props = {
|
|||||||
passwordComplexityPolicy: PasswordComplexityPolicy;
|
passwordComplexityPolicy: PasswordComplexityPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function submitRegister(values: Inputs) {
|
|
||||||
console.log(values);
|
|
||||||
// use fetch for local api
|
|
||||||
// return use(
|
|
||||||
// addHumanUser(server, {
|
|
||||||
// email: values.email,
|
|
||||||
// displayName: "huhu",
|
|
||||||
// password: values.password,
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function RegisterForm({
|
export default function RegisterForm({
|
||||||
privacyPolicy,
|
privacyPolicy,
|
||||||
passwordComplexityPolicy,
|
passwordComplexityPolicy,
|
||||||
@@ -50,6 +37,27 @@ export default function RegisterForm({
|
|||||||
mode: "onBlur",
|
mode: "onBlur",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function submitRegister(values: Inputs) {
|
||||||
|
const res = await fetch("/registeruser", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: values.email,
|
||||||
|
password: values.password,
|
||||||
|
firstName: values.firstname,
|
||||||
|
lastName: values.lastname,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("Failed to register user");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
const { errors } = formState;
|
const { errors } = formState;
|
||||||
|
|
||||||
const watchPassword = watch("password", "");
|
const watchPassword = watch("password", "");
|
||||||
@@ -102,7 +110,7 @@ export default function RegisterForm({
|
|||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
required
|
required
|
||||||
{...register("email", { required: "This field is required" })}
|
{...register("email", { required: "This field is required" })}
|
||||||
label="email"
|
label="E-mail"
|
||||||
error={errors.email?.message as string}
|
error={errors.email?.message as string}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user