mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-12 22:45:49 +00:00
refactor: update authentication flow to use NextAuth, replace better-auth with axios for API calls, and clean up unused code
This commit is contained in:
44
lib/auth.ts
44
lib/auth.ts
@ -1,44 +0,0 @@
|
||||
import { sendOtp } from "@/actions/auth-actions";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { prismaAdapter } from "better-auth/adapters/prisma";
|
||||
import { phoneNumber } from "better-auth/plugins";
|
||||
import prisma from "./db";
|
||||
|
||||
export const auth = betterAuth({
|
||||
session: {
|
||||
cookieCache: {
|
||||
enabled: true,
|
||||
maxAge: 10 * 60, // Cache duration in seconds
|
||||
},
|
||||
},
|
||||
trustedOrigins: process.env.BETTER_AUTH_TRUSTED_ORIGINS?.split(",") || [
|
||||
"localhost:3000",
|
||||
],
|
||||
user: {
|
||||
additionalFields: {
|
||||
role: {
|
||||
type: "string",
|
||||
required: false,
|
||||
defaultValue: "USER",
|
||||
input: false, // don't allow user to set role
|
||||
},
|
||||
lang: {
|
||||
type: "string",
|
||||
required: false,
|
||||
defaultValue: "en",
|
||||
},
|
||||
},
|
||||
},
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: "postgresql", // 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);
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
Reference in New Issue
Block a user