mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-06-29 15:47:09 +00:00
first commit
This commit is contained in:
7
lib/auth-client.ts
Normal file
7
lib/auth-client.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { phoneNumberClient } from "better-auth/client/plugins";
|
||||
import { createAuthClient } from "better-auth/react";
|
||||
|
||||
export const authClient = createAuthClient({
|
||||
baseURL: process.env.BETTER_AUTH_URL,
|
||||
plugins: [phoneNumberClient()],
|
||||
});
|
30
lib/auth.ts
Normal file
30
lib/auth.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { sendOtp } from "@/actions/auth-actions";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { prismaAdapter } from "better-auth/adapters/prisma";
|
||||
import { phoneNumber } from "better-auth/plugins";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
export const auth = betterAuth({
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: "sqlite", // or "mysql", "postgresql", ...etc
|
||||
}),
|
||||
plugins: [
|
||||
phoneNumber({
|
||||
sendOTP: async ({ phoneNumber, code }) => {
|
||||
// Implement sending OTP code via SMS
|
||||
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
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
17
lib/db.ts
Normal file
17
lib/db.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient();
|
||||
};
|
||||
|
||||
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClientSingleton | undefined;
|
||||
};
|
||||
|
||||
const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
|
||||
|
||||
export default prisma;
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
12
lib/schemas.ts
Normal file
12
lib/schemas.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { z } from "zod";
|
||||
export const signUpFormSchema = z.object({
|
||||
name: z.string().min(2, { message: "Name is required." }),
|
||||
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." }),
|
||||
dob: z.coerce.date({ message: "Date of birth is required." }),
|
||||
phoneNumber: z.string().min(7, { message: "Phone number is required." }),
|
||||
});
|
6
lib/utils.ts
Normal file
6
lib/utils.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
Reference in New Issue
Block a user