make user full name mandatory
This commit is contained in:
parent
9d30930f96
commit
9cec49f255
@ -4,12 +4,12 @@ import db, { GlobalRole, MembershipRole } from "../../../db";
|
|||||||
import { Signup } from "../validations";
|
import { Signup } from "../validations";
|
||||||
import { computeEncryptionKey } from "../../../db/_encryption";
|
import { computeEncryptionKey } from "../../../db/_encryption";
|
||||||
|
|
||||||
export default resolver.pipe(resolver.zod(Signup), async ({ email, password, name }, ctx) => {
|
export default resolver.pipe(resolver.zod(Signup), async ({ email, password, fullName }, ctx) => {
|
||||||
const hashedPassword = await SecurePassword.hash(password.trim());
|
const hashedPassword = await SecurePassword.hash(password.trim());
|
||||||
const encryptionKey = computeEncryptionKey(email.toLowerCase().trim()).toString("hex");
|
const encryptionKey = computeEncryptionKey(email.toLowerCase().trim()).toString("hex");
|
||||||
const user = await db.user.create({
|
const user = await db.user.create({
|
||||||
data: {
|
data: {
|
||||||
name: name.trim(),
|
fullName: fullName.trim(),
|
||||||
email: email.toLowerCase().trim(),
|
email: email.toLowerCase().trim(),
|
||||||
hashedPassword,
|
hashedPassword,
|
||||||
role: GlobalRole.CUSTOMER,
|
role: GlobalRole.CUSTOMER,
|
||||||
|
@ -40,7 +40,7 @@ const SignUp: BlitzPage = () => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LabeledTextField name="name" label="Name" type="text" />
|
<LabeledTextField name="fullName" label="Full name" type="text" />
|
||||||
<LabeledTextField name="email" label="Email" type="email" />
|
<LabeledTextField name="email" label="Email" type="email" />
|
||||||
<LabeledTextField name="password" label="Password" type="password" />
|
<LabeledTextField name="password" label="Password" type="password" />
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -3,7 +3,7 @@ import { z } from "zod";
|
|||||||
export const password = z.string().min(10).max(100);
|
export const password = z.string().min(10).max(100);
|
||||||
|
|
||||||
export const Signup = z.object({
|
export const Signup = z.object({
|
||||||
name: z.string(),
|
fullName: z.string(),
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,7 @@ import useCurrentUser from "../../core/hooks/use-current-user";
|
|||||||
import appLogger from "../../../integrations/logger";
|
import appLogger from "../../../integrations/logger";
|
||||||
|
|
||||||
type Form = {
|
type Form = {
|
||||||
name: string;
|
fullName: string;
|
||||||
email: string;
|
email: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,17 +30,17 @@ const ProfileInformations: FunctionComponent = () => {
|
|||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue("name", user?.name ?? "");
|
setValue("fullName", user?.fullName ?? "");
|
||||||
setValue("email", user?.email ?? "");
|
setValue("email", user?.email ?? "");
|
||||||
}, [setValue, user]);
|
}, [setValue, user]);
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async ({ name, email }) => {
|
const onSubmit = handleSubmit(async ({ fullName, email }) => {
|
||||||
if (isSubmitting) {
|
if (isSubmitting) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateUserMutation({ email, name });
|
await updateUserMutation({ email, fullName });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.error(error.response, "error updating user infos");
|
logger.error(error.response, "error updating user infos");
|
||||||
setErrorMessage(error.response.data.errorMessage);
|
setErrorMessage(error.response.data.errorMessage);
|
||||||
@ -68,16 +68,16 @@ const ProfileInformations: FunctionComponent = () => {
|
|||||||
<div className="shadow sm:rounded-md sm:overflow-hidden">
|
<div className="shadow sm:rounded-md sm:overflow-hidden">
|
||||||
<div className="px-4 py-5 bg-white space-y-6 sm:p-6">
|
<div className="px-4 py-5 bg-white space-y-6 sm:p-6">
|
||||||
<div className="col-span-3 sm:col-span-2">
|
<div className="col-span-3 sm:col-span-2">
|
||||||
<label htmlFor="name" className="block text-sm font-medium leading-5 text-gray-700">
|
<label htmlFor="fullName" className="block text-sm font-medium leading-5 text-gray-700">
|
||||||
Name
|
Full name
|
||||||
</label>
|
</label>
|
||||||
<div className="mt-1 rounded-md shadow-sm">
|
<div className="mt-1 rounded-md shadow-sm">
|
||||||
<input
|
<input
|
||||||
id="name"
|
id="fullName"
|
||||||
type="text"
|
type="text"
|
||||||
tabIndex={1}
|
tabIndex={1}
|
||||||
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md placeholder-gray-400 focus:outline-none focus:shadow-outline-primary focus:border-primary-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"
|
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md placeholder-gray-400 focus:outline-none focus:shadow-outline-primary focus:border-primary-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5"
|
||||||
{...register("name")}
|
{...register("fullName")}
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,17 +6,17 @@ import notifyEmailChangeQueue from "../api/queue/notify-email-change";
|
|||||||
|
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
name: z.string(),
|
fullName: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ email, name }, ctx) => {
|
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ email, fullName }, ctx) => {
|
||||||
const user = await db.user.findFirst({ where: { id: ctx.session.userId! } });
|
const user = await db.user.findFirst({ where: { id: ctx.session.userId! } });
|
||||||
if (!user) throw new NotFoundError();
|
if (!user) throw new NotFoundError();
|
||||||
|
|
||||||
const oldEmail = user.email;
|
const oldEmail = user.email;
|
||||||
await db.user.update({
|
await db.user.update({
|
||||||
where: { id: user.id },
|
where: { id: user.id },
|
||||||
data: { email, name },
|
data: { email, fullName },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (oldEmail !== email) {
|
if (oldEmail !== email) {
|
||||||
|
@ -9,7 +9,7 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) {
|
|||||||
where: { id: session.userId },
|
where: { id: session.userId },
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
fullName: true,
|
||||||
email: true,
|
email: true,
|
||||||
role: true,
|
role: true,
|
||||||
memberships: {
|
memberships: {
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `name` on the `User` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" DROP COLUMN "name",
|
||||||
|
ADD COLUMN "fullName" TEXT NOT NULL DEFAULT E'';
|
@ -69,7 +69,7 @@ model User {
|
|||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
createdAt DateTime @default(now()) @db.Timestamptz
|
createdAt DateTime @default(now()) @db.Timestamptz
|
||||||
updatedAt DateTime @updatedAt @db.Timestamptz
|
updatedAt DateTime @updatedAt @db.Timestamptz
|
||||||
name String?
|
fullName String @default("")
|
||||||
email String @unique
|
email String @unique
|
||||||
hashedPassword String?
|
hashedPassword String?
|
||||||
role GlobalRole @default(CUSTOMER)
|
role GlobalRole @default(CUSTOMER)
|
||||||
|
Loading…
Reference in New Issue
Block a user