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 { 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 encryptionKey = computeEncryptionKey(email.toLowerCase().trim()).toString("hex");
|
||||
const user = await db.user.create({
|
||||
data: {
|
||||
name: name.trim(),
|
||||
fullName: fullName.trim(),
|
||||
email: email.toLowerCase().trim(),
|
||||
hashedPassword,
|
||||
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="password" label="Password" type="password" />
|
||||
</Form>
|
||||
|
@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
export const password = z.string().min(10).max(100);
|
||||
|
||||
export const Signup = z.object({
|
||||
name: z.string(),
|
||||
fullName: z.string(),
|
||||
email: z.string().email(),
|
||||
password,
|
||||
});
|
||||
|
@ -12,7 +12,7 @@ import useCurrentUser from "../../core/hooks/use-current-user";
|
||||
import appLogger from "../../../integrations/logger";
|
||||
|
||||
type Form = {
|
||||
name: string;
|
||||
fullName: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
@ -30,17 +30,17 @@ const ProfileInformations: FunctionComponent = () => {
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
setValue("name", user?.name ?? "");
|
||||
setValue("fullName", user?.fullName ?? "");
|
||||
setValue("email", user?.email ?? "");
|
||||
}, [setValue, user]);
|
||||
|
||||
const onSubmit = handleSubmit(async ({ name, email }) => {
|
||||
const onSubmit = handleSubmit(async ({ fullName, email }) => {
|
||||
if (isSubmitting) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await updateUserMutation({ email, name });
|
||||
await updateUserMutation({ email, fullName });
|
||||
} catch (error: any) {
|
||||
logger.error(error.response, "error updating user infos");
|
||||
setErrorMessage(error.response.data.errorMessage);
|
||||
@ -68,16 +68,16 @@ const ProfileInformations: FunctionComponent = () => {
|
||||
<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="col-span-3 sm:col-span-2">
|
||||
<label htmlFor="name" className="block text-sm font-medium leading-5 text-gray-700">
|
||||
Name
|
||||
<label htmlFor="fullName" className="block text-sm font-medium leading-5 text-gray-700">
|
||||
Full name
|
||||
</label>
|
||||
<div className="mt-1 rounded-md shadow-sm">
|
||||
<input
|
||||
id="name"
|
||||
id="fullName"
|
||||
type="text"
|
||||
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"
|
||||
{...register("name")}
|
||||
{...register("fullName")}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
@ -6,17 +6,17 @@ import notifyEmailChangeQueue from "../api/queue/notify-email-change";
|
||||
|
||||
const Body = z.object({
|
||||
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! } });
|
||||
if (!user) throw new NotFoundError();
|
||||
|
||||
const oldEmail = user.email;
|
||||
await db.user.update({
|
||||
where: { id: user.id },
|
||||
data: { email, name },
|
||||
data: { email, fullName },
|
||||
});
|
||||
|
||||
if (oldEmail !== email) {
|
||||
|
@ -9,7 +9,7 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) {
|
||||
where: { id: session.userId },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
fullName: true,
|
||||
email: true,
|
||||
role: true,
|
||||
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())
|
||||
createdAt DateTime @default(now()) @db.Timestamptz
|
||||
updatedAt DateTime @updatedAt @db.Timestamptz
|
||||
name String?
|
||||
fullName String @default("")
|
||||
email String @unique
|
||||
hashedPassword String?
|
||||
role GlobalRole @default(CUSTOMER)
|
||||
|
Loading…
Reference in New Issue
Block a user