export const auth = betterAuth({
database: drizzleAdapter(db, { provider: "pg" }),
secondaryStorage: {
get: async (key) => {
const value = await redis.get(key);
return JSON.stringify(value) || null;
},
set: async (key, value, ttl) => {
const opt = ttl ? { ex: ttl } : undefined;
await redis.set(key, value, opt);
},
delete: async (key) => {
await redis.del(key);
},
prefix: "myauth",
},
rateLimit: {
enabled: true,
window: 60,
max: 10,
storage: "secondary-storage",
// customStorage: {
// get: async (key) => {
// const data = await redis.get(key);
// console.log({ data });
// return data ? JSON.parse(data as string) : undefined;
// },
// set: async (key, value) => {
// await redis.set(key, JSON.stringify(value), { ex: 60 });
// },
// },
},
emailAndPassword: {
enabled: true,
minPasswordLength: 6,
maxPasswordLength: 64,
autoSignIn: false,
requireEmailVerification: true,
sendResetPassword: async ({ user, url }) => {
await sendMail({
to: [user.email],
...getAuthMailProps({ name: user.name, url, type: "reset" }),
});
},
},
}
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: "pg" }),
secondaryStorage: {
get: async (key) => {
const value = await redis.get(key);
return JSON.stringify(value) || null;
},
set: async (key, value, ttl) => {
const opt = ttl ? { ex: ttl } : undefined;
await redis.set(key, value, opt);
},
delete: async (key) => {
await redis.del(key);
},
prefix: "myauth",
},
rateLimit: {
enabled: true,
window: 60,
max: 10,
storage: "secondary-storage",
// customStorage: {
// get: async (key) => {
// const data = await redis.get(key);
// console.log({ data });
// return data ? JSON.parse(data as string) : undefined;
// },
// set: async (key, value) => {
// await redis.set(key, JSON.stringify(value), { ex: 60 });
// },
// },
},
emailAndPassword: {
enabled: true,
minPasswordLength: 6,
maxPasswordLength: 64,
autoSignIn: false,
requireEmailVerification: true,
sendResetPassword: async ({ user, url }) => {
await sendMail({
to: [user.email],
...getAuthMailProps({ name: user.name, url, type: "reset" }),
});
},
},
}