refactor: identity -> iam
This commit is contained in:
29
modules/iam/services/auth.ts
Normal file
29
modules/iam/services/auth.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { logger } from "@platform/logger";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
||||
import { emailOTP } from "better-auth/plugins";
|
||||
|
||||
import { db } from "./database.ts";
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: mongodbAdapter(db.db),
|
||||
session: {
|
||||
cookieCache: {
|
||||
enabled: true,
|
||||
maxAge: 5 * 60, // Cache duration in seconds
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
emailOTP({
|
||||
async sendVerificationOTP({ email, otp, type }) {
|
||||
if (type === "sign-in") {
|
||||
logger.info({ email, otp, type });
|
||||
} else if (type === "email-verification") {
|
||||
// Send the OTP for email verification
|
||||
} else {
|
||||
// Send the OTP for password reset
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user