mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
field added
This commit is contained in:
parent
9263d1063c
commit
6492c4483e
@ -11,104 +11,120 @@ let emailError: string | null = null;
|
||||
let passwordError: string | null = null;
|
||||
|
||||
export default function RegisterPage() {
|
||||
async function handleSubmit(data: FormData) {
|
||||
'use server';
|
||||
const res = await createCustomer({
|
||||
variables: {
|
||||
input: {
|
||||
email: data.get('email') as string,
|
||||
password: data.get('password') as string,
|
||||
},
|
||||
},
|
||||
});
|
||||
async function handleSubmit(data: FormData) {
|
||||
'use server';
|
||||
const res = await createCustomer({
|
||||
variables: {
|
||||
input: {
|
||||
email: data.get('email') as string,
|
||||
password: data.get('password') as string,
|
||||
firstName: data.get('firstname') as string,
|
||||
lastName: data.get('lastname') as string
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (res.body.data.customerCreate.customer) {
|
||||
const loginRes = await loginCustomer({
|
||||
variables: {
|
||||
input: {
|
||||
email: data.get('email') as string,
|
||||
password: data.get('password') as string,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (res.body.data.customerCreate.customer) {
|
||||
const loginRes = await loginCustomer({
|
||||
variables: {
|
||||
input: {
|
||||
email: data.get('email') as string,
|
||||
password: data.get('password') as string,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
loginRes.body.data.customerAccessTokenCreate.customerAccessToken
|
||||
?.accessToken
|
||||
) {
|
||||
cookies().set({
|
||||
name: 'customerAccessToken',
|
||||
value:
|
||||
loginRes.body.data.customerAccessTokenCreate.customerAccessToken
|
||||
.accessToken,
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
expires: new Date(Date.now() + 20 * 60 * 1000 + 5 * 1000),
|
||||
});
|
||||
redirect('/account');
|
||||
}
|
||||
if (loginRes.body.data.customerAccessTokenCreate.customerAccessToken?.accessToken) {
|
||||
cookies().set({
|
||||
name: 'customerAccessToken',
|
||||
value: loginRes.body.data.customerAccessTokenCreate.customerAccessToken.accessToken,
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
expires: new Date(Date.now() + 20 * 60 * 1000 + 5 * 1000)
|
||||
});
|
||||
redirect('/account');
|
||||
}
|
||||
|
||||
redirect('/account/login');
|
||||
}
|
||||
redirect('/account/login');
|
||||
}
|
||||
|
||||
if (res.body.data.customerCreate.customerUserErrors.length > 0) {
|
||||
res.body.data.customerCreate.customerUserErrors.filter((error: any) => {
|
||||
if (error.field.includes('email')) {
|
||||
emailError = error.message;
|
||||
}
|
||||
if (error.field.includes('password')) {
|
||||
passwordError = error.message;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (res.body.data.customerCreate.customerUserErrors.length > 0) {
|
||||
res.body.data.customerCreate.customerUserErrors.filter((error: any) => {
|
||||
if (error.field.includes('email')) {
|
||||
emailError = error.message;
|
||||
}
|
||||
if (error.field.includes('password')) {
|
||||
passwordError = error.message;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath('/account/register');
|
||||
}
|
||||
revalidatePath('/account/register');
|
||||
}
|
||||
|
||||
return (
|
||||
<AuthLayout>
|
||||
<FormHeader title="Create an Account" />
|
||||
<form
|
||||
action={handleSubmit}
|
||||
noValidate
|
||||
className="pt-6 pb-8 mt-4 mb-4 space-y-3"
|
||||
>
|
||||
<div>
|
||||
<input
|
||||
className={`mb-1`}
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
placeholder="Email address"
|
||||
aria-label="Email address"
|
||||
autoFocus
|
||||
/>
|
||||
{emailError && (
|
||||
<p className="text-red-500 text-xs">{emailError} </p>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<input
|
||||
className={`mb-1`}
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
placeholder="Password"
|
||||
aria-label="Password"
|
||||
minLength={8}
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
{passwordError && (
|
||||
<p className="text-red-500 text-xs"> {passwordError} </p>
|
||||
)}
|
||||
</div>
|
||||
<FormButton btnText="Create Account" />
|
||||
<FormFooter page="register" />
|
||||
</form>
|
||||
</AuthLayout>
|
||||
);
|
||||
return (
|
||||
<AuthLayout>
|
||||
<FormHeader title="Create an Account" />
|
||||
<form action={handleSubmit} noValidate className="mb-4 mt-4 space-y-3 pb-8 pt-6">
|
||||
<div>
|
||||
<input
|
||||
className={`mb-1`}
|
||||
id="firstname"
|
||||
name="firstname"
|
||||
type="text"
|
||||
required
|
||||
placeholder="First Name"
|
||||
aria-label="First Name"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input
|
||||
className={`mb-1`}
|
||||
id="lastname"
|
||||
name="lastname"
|
||||
type="text"
|
||||
autoComplete="email"
|
||||
required
|
||||
placeholder="Last Name"
|
||||
aria-label="Last Name"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input
|
||||
className={`mb-1`}
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
placeholder="Email address"
|
||||
aria-label="Email address"
|
||||
autoFocus
|
||||
/>
|
||||
{emailError && <p className="text-xs text-red-500">{emailError} </p>}
|
||||
</div>
|
||||
<div>
|
||||
<input
|
||||
className={`mb-1`}
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
placeholder="Password"
|
||||
aria-label="Password"
|
||||
minLength={8}
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
{passwordError && <p className="text-xs text-red-500"> {passwordError} </p>}
|
||||
</div>
|
||||
<FormButton btnText="Create Account" />
|
||||
<FormFooter page="register" />
|
||||
</form>
|
||||
</AuthLayout>
|
||||
);
|
||||
}
|
||||
|
@ -301,6 +301,8 @@ export async function createCustomer({
|
||||
input: {
|
||||
email: string;
|
||||
password: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
};
|
||||
}) {
|
||||
@ -312,6 +314,8 @@ export async function createCustomer({
|
||||
input: {
|
||||
email: string;
|
||||
password: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
};
|
||||
};
|
||||
}>({
|
||||
|
Loading…
x
Reference in New Issue
Block a user