mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-12 10:25:49 +00:00
first commit
This commit is contained in:
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
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
Reference in New Issue
Block a user