This commit is contained in:
i701 2024-11-27 07:48:16 +05:00
parent 7389de4c76
commit 7fadcd561f
17 changed files with 454 additions and 189 deletions

View File

@ -2,10 +2,11 @@
import { authClient } from "@/lib/auth-client";
import prisma from "@/lib/db";
import type { signUpFormSchema } from "@/lib/schemas";
import { signUpFormSchema } from "@/lib/schemas";
// import type { User } from "@prisma/client";
import { redirect } from "next/navigation";
import { z } from "zod";
import { headers } from "next/headers";
const formSchema = z.object({
phoneNumber: z
.string()
@ -13,7 +14,7 @@ const formSchema = z.object({
});
export async function signin(
currentState: { message: string; status: string },
previousState: ActionState,
formData: FormData,
) {
const phoneNumber = formData.get("phoneNumber") as string;
@ -46,17 +47,78 @@ export async function signin(
await authClient.phoneNumber.sendOtp({
phoneNumber: NUMBER_WITH_COUNTRY_CODE,
});
redirect("/verify-otp");
redirect(`/verify-otp?phone_number=${encodeURIComponent(phoneNumber)}`);
}
export async function signup({
userData,
}: { userData: z.infer<typeof signUpFormSchema> }) {
const newUser = await prisma.user.create({
data: { ...userData, email: "" },
});
type ActionState = {
message: string;
payload?: FormData;
};
redirect("/login");
export async function signup(
_actionState: ActionState,
formData: FormData,
) {
const data = Object.fromEntries(formData.entries());
const parsedData = signUpFormSchema.safeParse(data);
// get phone number from /signup?phone_number=999-1231
const headersList = await headers()
const referer = headersList.get("referer")
const number = referer?.split("?")[1]?.split("=")[1]
let NUMBER_WITH_COUNTRY_CODE: string
console.log(data)
if (!parsedData.success) {
return {
message: "Invalid form data",
payload: formData,
errors: parsedData.error.flatten(),
};
}
if (parsedData.data.name.includes("a")){
return {
message: "ID card already exists.",
payload: formData,
db_error: "id_card",
};
}
if (number) {
NUMBER_WITH_COUNTRY_CODE = `+960${number.split("-").join("")}`
} else {
NUMBER_WITH_COUNTRY_CODE = `+960${parsedData.data.phone_number.split("-").join("")}`;
}
console.log({NUMBER_WITH_COUNTRY_CODE})
const idCardExists = await prisma.user.findFirst({
where: {
id_card: parsedData.data.id_card,
},
});
if (idCardExists) {
return {
message: "ID card already exists.",
payload: formData,
db_error: "id_card",
};
}
// const newUser = await prisma.user.create({
// data: {
// name: parsedData.data.name,
// islandId: "1",
// atollId: "1",
// house_name: parsedData.data.house_name,
// id_card: parsedData.data.id_card,
// dob: parsedData.data.dob,
// phoneNumber: NUMBER_WITH_COUNTRY_CODE,
// },
// });
// await authClient.phoneNumber.sendOtp({
// phoneNumber: newUser.phoneNumber,
// });
// redirect(`/verify-otp?phone_number=${encodeURIComponent(newUser.phoneNumber)}`);
return { message: "Post created" };
}
export const sendOtp = async (phoneNumber: string, code: string) => {

View File

@ -1,8 +1,14 @@
import SignUpForm from "@/components/auth/signup-form";
import prisma from "@/lib/db";
import Image from "next/image";
import React from "react";
export default function LoginPage() {
export default async function LoginPage() {
const atolls = await prisma.atoll.findMany({
include: {
islands: true
}
})
return <div className="bg-gray-100 dark:bg-black w-full h-screen flex items-center justify-center font-sans">
<div className="flex flex-col items-center justify-center w-full h-full ">
<Image priority alt="Sar Link Logo" src="/logo.png" width={100} height={100} />
@ -11,7 +17,7 @@ export default function LoginPage() {
<h4 className="font-bold text-xl text-gray-600">SAR Link Portal</h4>
<p className="text-gray-500">Pay for your devices and track your bills.</p>
</div>
<SignUpForm />
<SignUpForm atolls={atolls} />
</div>
</div>;
}

View File

@ -2,7 +2,12 @@ import VerifyOTPForm from "@/components/auth/verify-otp-form";
import Image from "next/image";
import React from "react";
export default function VerifyOTP() {
export default async function VerifyOTP({
searchParams,
}: {
searchParams: Promise<{ phone_number: string }>
}) {
const phone_number = (await searchParams).phone_number
return <div className="bg-gray-100 dark:bg-black w-full h-screen flex items-center justify-center font-sans">
<div className="flex flex-col items-center justify-center w-full h-full ">
<Image alt="Sar Link Logo" src="/logo.png" width={100} height={100} />
@ -11,7 +16,7 @@ export default function VerifyOTP() {
<h4 className="font-bold text-xl text-gray-600">SAR Link Portal</h4>
<p className="text-gray-500">Pay for your devices and track your bills.</p>
</div>
<VerifyOTPForm />
<VerifyOTPForm phone_number={phone_number} />
</div>
</div>;
}

View File

@ -25,7 +25,7 @@ export default function RootLayout({
<html lang="en" suppressHydrationWarning>
<body className={`${barlow.variable} antialiased font-sans`}>
<NextTopLoader showSpinner={false} zIndex={9999} />
<Toaster />
<Toaster richColors />
<ThemeProvider
attribute="class"
defaultTheme="system"

View File

@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button";
import { signin } from "@/actions/auth-actions";
import { Loader } from "lucide-react";
import Link from "next/link";
import { useActionState } from "react";
import { PhoneInput } from "../ui/phone-input";
@ -17,8 +16,7 @@ export default function LoginForm() {
return (
<form className="bg-white overflow-clip dark:bg-transparent dark:border-2 w-full max-w-xs mx-auto rounded-lg shadow mt-4" action={formAction}>
<h4 className="text-center rounded m-2 text-xl font-bold dark:text-white text-gray-600 dark:bg-gray-900 bg-gray-200 py-4">Login</h4>
<div className="py-2 px-10">
<div className="py-6 px-10">
<div className="grid gap-4">
<PhoneInput
id="phone-number"
@ -35,12 +33,12 @@ export default function LoginForm() {
{isPending ? <Loader className="animate-spin" /> : "Request OTP"}
</Button>
</div>
<div className="my-4 text-center text-sm">
{/* <div className="mt-2 text-center text-sm">
Don&apos;t have an account?{" "}
<Link href="signup" className="underline">
Sign up
</Link>
</div>
</div> */}
</div>
</form>
);

View File

@ -1,167 +1,241 @@
"use client";
import { Button } from "@/components/ui/button";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { signUpFormSchema } from "@/lib/schemas";
import { zodResolver } from "@hookform/resolvers/zod";
import Link from "next/link";
import { signup } from "@/actions/auth-actions";
import { cn } from "@/lib/utils";
import { Loader } from "lucide-react";
import { useActionState } from "react";
import { useSearchParams } from "next/navigation";
import { Atoll, Island, Prisma } from "@prisma/client";
import * as React from "react"
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import type { z } from "zod";
import { DatePicker } from "../ui/datepicker";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
export default function SignUpForm() {
const params = useSearchParams();
console.log(params);
const phone_number = params.get("phone_number");
const form = useForm<z.infer<typeof signUpFormSchema>>({
resolver: zodResolver(signUpFormSchema),
defaultValues: {
phoneNumber: phone_number ?? "",
name: "",
id_card: "",
house_name: "",
island: "F.Dharanboodhoo",
},
});
function onSubmit(values: z.infer<typeof signUpFormSchema>) {
console.log(values);
type AtollWithIslands = Prisma.AtollGetPayload<{
include: {
islands: true;
}
}>
export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) {
const [atoll, setAtoll] = React.useState<AtollWithIslands>()
const [island, setIsland] = React.useState<string>()
const [actionState, action, isPending] = useActionState(signup, {
message: "",
});
const params = useSearchParams();
const phoneNumberFromUrl = params.get("phone_number");
const NUMBER_WITHOUT_DASH = phoneNumberFromUrl?.split("-").join("")
return (
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="max-w-xs w-full bg-white dark:bg-transparent dark:border-2 shadow rounded-lg mx-auto"
>
<h4 className="text-center rounded m-2 text-xl font-bold text-gray-600 bg-gray-200 py-4">
Sign up
</h4>
<div className="py-2 px-4 my-2">
<FormField
control={form.control}
<form
action={action}
className="max-w-xs mt-4 w-full bg-white dark:bg-transparent dark:border-2 shadow rounded-lg mx-auto"
>
<div className="py-2 px-4 my-2 space-y-2">
<div>
<label htmlFor="name" className="text-sm">Name</label>
<Input
className={cn(
'text-base',
actionState.errors?.fieldErrors.name && 'border-2 border-red-500',
)}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input placeholder="eg: Shihaam" type="text" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
type="text"
defaultValue={(actionState.payload?.get("name") || "") as string}
placeholder="Full Name"
/>
<FormField
control={form.control}
{actionState.errors?.fieldErrors.name && (
<span className="text-sm inline-block text-red-500">
{actionState.errors?.fieldErrors.name}
</span>
)}
</div>
<div>
<label htmlFor="id_card" className="text-sm">ID Card</label>
<Input
name="id_card"
render={({ field }) => (
<FormItem>
<FormLabel>ID Card</FormLabel>
<FormControl>
<Input placeholder="Axxxxxx" type="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
type="text"
maxLength={7}
defaultValue={(actionState.payload?.get("id_card") || "") as string}
className={cn(
'text-base',
actionState.errors?.fieldErrors?.id_card && 'border-2 border-red-500',
)}
placeholder="ID Card"
/>
<FormField
control={form.control}
name="island"
render={({ field }) => (
<FormItem>
<FormLabel>Island</FormLabel>
<FormControl>
<Input
placeholder="F.Dharanboodhoo"
disabled
type=""
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
{actionState?.errors?.fieldErrors?.id_card?.[0] && (
<span className="text-sm inline-block text-red-500">
{actionState.errors.fieldErrors.id_card[0]}
</span>
)}
{actionState.db_error === "id_card" && (
<span className="text-sm inline-block text-red-500">
{actionState.message}
</span>
)}
</div>
<div>
{/* <label htmlFor="island_name" className="text-sm">Island Name</label>
<Input
name="island_name"
type="text"
defaultValue={"F.Dharaboondhoo"}
className={cn(
'text-base cursor-not-allowed',
actionState.errors?.fieldErrors?.island_name && 'border-2 border-red-500',
)}
readOnly
/>
<FormField
control={form.control}
{actionState?.errors?.fieldErrors.island_name && (
<span className="text-sm inline-block text-red-500">
{actionState?.errors?.fieldErrors.island_name}
</span>
)} */}
<div>
<label htmlFor="atoll" className="text-sm">Atoll</label>
<Select onValueChange={(v) => {
setAtoll(atolls.find((atoll) => atoll.id === v))
setIsland("")
}} name="atoll_id" value={atoll?.id}>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select atoll" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Atolls</SelectLabel>
{atolls.map((atoll) => (
<SelectItem key={atoll.id} value={atoll.id}>
{atoll.name}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
{actionState.errors?.fieldErrors?.atoll_id && (
<span className="text-sm inline-block text-red-500">
{actionState.errors?.fieldErrors?.atoll_id}
</span>
)}
</Select>
</div>
<div>
<label htmlFor="island" className="text-sm">Island</label>
<Select
name="island_id">
<SelectTrigger className="w-full">
<SelectValue placeholder="Select island" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Islands</SelectLabel>
{atoll?.islands.map((island) => (
<SelectItem key={island.id} value={island.id}>
{island.name}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
{actionState.errors?.fieldErrors?.island_id && (
<span className="text-sm inline-block text-red-500">
{actionState.errors?.fieldErrors?.island_id}
</span>
)}
</Select>
</div>
</div>
<div>
<label htmlFor="house_name" className="text-sm">House Name</label>
<Input
className={cn(
'text-base',
actionState.errors?.fieldErrors?.house_name && 'border-2 border-red-500',
)}
name="house_name"
render={({ field }) => (
<FormItem>
<FormLabel>House Name</FormLabel>
<FormControl>
<Input placeholder="eg: Skyvilla" type="text" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
defaultValue={(actionState.payload?.get("house_name") || "") as string}
type="text"
placeholder="House Name"
/>
<FormField
control={form.control}
{actionState.errors?.fieldErrors?.house_name && (
<span className="text-sm inline-block text-red-500">
{actionState.errors?.fieldErrors?.house_name}
</span>
)}
</div>
<div>
<label htmlFor="dob" className="text-sm">Date of Birth</label>
<Input
className={cn(
'text-base',
actionState.errors?.fieldErrors?.dob && 'border-2 border-red-500',
)}
name="dob"
render={({ field }) => (
<FormItem className="flex flex-col mt-2">
<FormLabel>Date of birth</FormLabel>
<DatePicker
date={field.value}
setDate={field.onChange}
/>
<FormMessage />
</FormItem>
)}
defaultValue={(actionState.payload?.get("dob") || "") as string}
type="date"
placeholder="Date of birth"
/>
<FormField
control={form.control}
name="phoneNumber"
render={({ field }) => (
<FormItem className="flex flex-col items-start mt-2">
<FormLabel>Phone number</FormLabel>
<FormControl className="w-full">
<div className="flex rounded-lg shadow-sm shadow-black/5">
<div className="relative">
<span
className="peer inline-flex h-full appearance-none items-center rounded-none rounded-s-lg border border-input bg-background pe-4 ps-3 text-sm text-muted-foreground transition-shadow hover:bg-accent hover:text-accent-foreground focus:z-10 focus-visible:border-ring focus-visible:text-foreground focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/20 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
aria-label="Protocol"
>
<option value="https://">+960</option>
</span>
</div>
<Input
className="-ms-px rounded-s-none shadow-none focus-visible:z-10"
// disabled={Boolean(phone_number ?? "")}
placeholder="9xxxxxx / 7xxxxxx"
{...field}
/>
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button className="mt-4 w-full" type="submit">
Submit
</Button>
</div>
<div className="mb-4 text-center text-sm">
Already have an account?{" "}
<Link href="login" className="underline">
login
</Link>
{actionState.errors?.fieldErrors?.dob && (
<span className="text-sm inline-block text-red-500">
{actionState.errors?.fieldErrors?.dob}
</span>
)}
</div>
</form>
</Form>
<div>
<label htmlFor="phone_number" className="text-sm">Phone Number</label>
<Input
id="phone-number"
name="phone_number"
maxLength={8}
className={cn(!phoneNumberFromUrl && actionState.errors?.fieldErrors?.phone_number && "border-2 border-red-500 rounded-md",)}
defaultValue={NUMBER_WITHOUT_DASH ?? ""}
readOnly={Boolean(phoneNumberFromUrl)}
placeholder={phoneNumberFromUrl ?? "Phone number"}
/>
</div>
{actionState?.errors?.fieldErrors?.phone_number?.[0] && (
<span className="text-sm inline-block text-red-500">
{actionState.errors.fieldErrors.phone_number[0]}
</span>
)}
<Button disabled={isPending} className="mt-4 w-full" type="submit">
{isPending ? <Loader className="animate-spin" /> : "Submit"}
</Button>
</div>
<div className="mb-4 text-center text-sm">
Already have an account?{" "}
<Link href="login" className="underline">
login
</Link>
</div>
</form>
);
}

View File

@ -15,14 +15,13 @@ import { z } from "zod";
const OTPSchema = z.object({
pin: z.string().min(6, {
message: "Your one-time password must be 6 characters.",
}),
});
export default function VerifyOTPForm() {
export default function VerifyOTPForm({ phone_number }: { phone_number: string }) {
const [isPending, startTransition] = useTransition();
const router = useRouter();
console.log("verification in OTP form", phone_number)
const {
register,
handleSubmit,
@ -35,13 +34,13 @@ export default function VerifyOTPForm() {
});
const onSubmit: SubmitHandler<z.infer<typeof OTPSchema>> = (data) => {
console.log(data);
startTransition(async () => {
const isVerified = await authClient.phoneNumber.verify({
phoneNumber: "+9607780588",
phoneNumber: phone_number,
code: data.pin,
});
console.log({ isVerified });
if (!isVerified.error) {
router.push("/devices");
} else {
@ -53,9 +52,8 @@ export default function VerifyOTPForm() {
return (
<form
onSubmit={handleSubmit(onSubmit)}
className="bg-white dark:bg-gray-900 w-full max-w-xs rounded-lg shadow my-4 "
className="bg-white dark:bg-gray-900 w-full max-w-xs rounded-lg shadow my-4"
>
<h4 className="text-center rounded m-2 text-xl font-bold text-gray-600 bg-gray-200 py-4">Verify OTP</h4>
<div className="grid pb-4 pt-2 gap-4 px-10">
<div className="">
<Label htmlFor="otp-number" className="text-gray-500">

View File

@ -16,15 +16,6 @@ export const auth = betterAuth({
console.log("Send OTP in auth.ts", phoneNumber, code);
await sendOtp(phoneNumber, code);
},
signUpOnVerification: {
getTempEmail: (phoneNumber) => {
return `${phoneNumber}@my-site.com`;
},
//optionally you can alos pass `getTempName` function to generate a temporary name for the user
getTempName: (phoneNumber) => {
return phoneNumber; //by default it will use the phone number as the name
},
},
}),
],
});

View File

@ -4,9 +4,10 @@ export const signUpFormSchema = z.object({
id_card: z
.string()
.min(2, { message: "ID Card is required" })
.regex(/^[A][0-9]{6}$/, "Please enter a valid phone ID Card number."),
island: z.string().min(2, { message: "Island is required." }),
house_name: z.string().min(5, { message: "House name is required." }),
.regex(/^[A][0-9]{6}$/, "Please enter a valid ID Card number."),
atoll_id: z.string().min(2, { message: "Atoll is required." }),
island_id: z.string().min(2, { message: "Island is required." }),
house_name: z.string().min(2, { message: "House name is required." }),
dob: z.coerce.date({ message: "Date of birth is required." }),
phoneNumber: z.string().min(7, { message: "Phone number is required." }),
phone_number: z.string().min(7, { message: "Phone number is required." }).regex(/^[79][0-9]{2}[0-9]{4}$/, "Please enter a valid phone number").transform((val) => val.replace(/\D/g, "")),
});

View File

@ -0,0 +1,11 @@
/*
Warnings:
- A unique constraint covering the columns `[id_card]` on the table `user` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "user" ADD COLUMN "id_card" TEXT;
-- CreateIndex
CREATE UNIQUE INDEX "user_id_card_key" ON "user"("id_card");

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "user" ADD COLUMN "island" TEXT;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "user" ADD COLUMN "house_name" TEXT;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "user" ADD COLUMN "dob" DATETIME;

View File

@ -0,0 +1,30 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_user" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT,
"email" TEXT,
"emailVerified" BOOLEAN NOT NULL DEFAULT false,
"firstPaymentDone" BOOLEAN NOT NULL DEFAULT false,
"verified" BOOLEAN NOT NULL DEFAULT false,
"island" TEXT,
"house_name" TEXT,
"id_card" TEXT,
"dob" DATETIME,
"image" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"phoneNumber" TEXT NOT NULL,
"phoneNumberVerified" BOOLEAN NOT NULL DEFAULT false,
"role" TEXT,
"lang" TEXT
);
INSERT INTO "new_user" ("createdAt", "dob", "email", "emailVerified", "firstPaymentDone", "house_name", "id", "id_card", "image", "island", "lang", "name", "phoneNumber", "phoneNumberVerified", "role", "updatedAt", "verified") SELECT "createdAt", "dob", "email", "emailVerified", "firstPaymentDone", "house_name", "id", "id_card", "image", "island", "lang", "name", "phoneNumber", "phoneNumberVerified", "role", "updatedAt", "verified" FROM "user";
DROP TABLE "user";
ALTER TABLE "new_user" RENAME TO "user";
CREATE UNIQUE INDEX "user_email_key" ON "user"("email");
CREATE UNIQUE INDEX "user_id_card_key" ON "user"("id_card");
CREATE UNIQUE INDEX "user_phoneNumber_key" ON "user"("phoneNumber");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@ -0,0 +1,17 @@
-- CreateTable
CREATE TABLE "Atoll" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "Island" (
"id" TEXT NOT NULL PRIMARY KEY,
"atollId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "Island_atollId_fkey" FOREIGN KEY ("atollId") REFERENCES "Atoll" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

View File

@ -0,0 +1,39 @@
/*
Warnings:
- You are about to drop the column `island` on the `user` table. All the data in the column will be lost.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_user" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT,
"email" TEXT,
"emailVerified" BOOLEAN NOT NULL DEFAULT false,
"firstPaymentDone" BOOLEAN NOT NULL DEFAULT false,
"verified" BOOLEAN NOT NULL DEFAULT false,
"house_name" TEXT,
"id_card" TEXT,
"dob" DATETIME,
"image" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"phoneNumber" TEXT NOT NULL,
"phoneNumberVerified" BOOLEAN NOT NULL DEFAULT false,
"role" TEXT,
"lang" TEXT,
"atollId" TEXT,
"islandId" TEXT,
CONSTRAINT "user_atollId_fkey" FOREIGN KEY ("atollId") REFERENCES "Atoll" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "user_islandId_fkey" FOREIGN KEY ("islandId") REFERENCES "Island" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_user" ("createdAt", "dob", "email", "emailVerified", "firstPaymentDone", "house_name", "id", "id_card", "image", "lang", "name", "phoneNumber", "phoneNumberVerified", "role", "updatedAt", "verified") SELECT "createdAt", "dob", "email", "emailVerified", "firstPaymentDone", "house_name", "id", "id_card", "image", "lang", "name", "phoneNumber", "phoneNumberVerified", "role", "updatedAt", "verified" FROM "user";
DROP TABLE "user";
ALTER TABLE "new_user" RENAME TO "user";
CREATE UNIQUE INDEX "user_email_key" ON "user"("email");
CREATE UNIQUE INDEX "user_id_card_key" ON "user"("id_card");
CREATE UNIQUE INDEX "user_phoneNumber_key" ON "user"("phoneNumber");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@ -14,12 +14,18 @@ datasource db {
}
model User {
id String @id @default(cuid())
id String @id @default(cuid())
name String?
email String @unique
emailVerified Boolean @default(false)
firstPaymentDone Boolean @default(false)
verified Boolean @default(false)
email String? @unique
emailVerified Boolean @default(false)
firstPaymentDone Boolean @default(false)
verified Boolean @default(false)
// island String?
house_name String?
id_card String? @unique
dob DateTime?
atoll Atoll? @relation(fields: [atollId], references: [id])
island Island? @relation(fields: [islandId], references: [id])
image String?
createdAt DateTime @default(now())
@ -27,8 +33,10 @@ model User {
phoneNumber String @unique
phoneNumberVerified Boolean @default(false)
role String?
lang String?
role String?
lang String?
atollId String?
islandId String?
@@map("user")
}
@ -75,3 +83,22 @@ model Verification {
@@map("verification")
}
model Atoll {
id String @id @default(cuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
islands Island[]
User User[]
}
model Island {
id String @id @default(cuid())
atollId String
atoll Atoll @relation(fields: [atollId], references: [id])
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
User User[]
}