77 VerificationEmail ,
88} from "@databuddy/email" ;
99import { getRedisCache } from "@databuddy/redis" ;
10- import { logger } from "@databuddy/shared/logger" ;
1110import { betterAuth } from "better-auth" ;
1211
1312import { drizzleAdapter } from "better-auth/adapters/drizzle" ;
@@ -32,15 +31,7 @@ export const auth = betterAuth({
3231 databaseHooks : {
3332 user : {
3433 create : {
35- after : async ( user : { id : string ; name : string ; email : string } ) => {
36- logger . info (
37- {
38- userId : user . id ,
39- userName : user . name ,
40- userEmail : user . email ,
41- } ,
42- "User Created"
43- ) ;
34+ after : async ( ) => {
4435 // const resend = new Resend(process.env.RESEND_API_KEY as string);
4536 // await resend.emails.send({
4637 // from: "Databuddy <[email protected] >", @@ -56,50 +47,30 @@ export const auth = betterAuth({
5647 deleteUser : {
5748 enabled : true ,
5849 beforeDelete : async ( user ) => {
59- logger . info (
60- "User Deletion Started" ,
61- `Starting deletion process for user ${ user . id } `
62- ) ;
63-
6450 try {
6551 const userWebsites = await db . query . websites . findMany ( {
6652 where : eq ( websites . userId , user . id ) ,
6753 } ) ;
6854
6955 if ( userWebsites . length > 0 ) {
70- logger . info (
71- "Deleting Websites" ,
72- `Deleting websites for user ${ user . id } `
73- ) ;
7456 await db . delete ( websites ) . where (
7557 inArray (
7658 websites . id ,
7759 userWebsites . map ( ( w ) => w . id )
7860 )
7961 ) ;
8062 }
81- logger . info (
82- "User Deletion Finished" ,
83- `Finished deletion process for user ${ user . id } `
84- ) ;
8563 } catch ( error ) {
86- logger . exception ( error as Error , { user : user . id } ) ;
64+ console . error ( error ) ;
8765 }
8866 } ,
8967 } ,
9068 } ,
9169 appName : "databuddy.cc" ,
9270 onAPIError : {
9371 throw : false ,
94- onError : ( error , ctx ) => {
95- if ( error instanceof Error ) {
96- logger . exception ( error , ctx as Record < string , unknown > ) ;
97- } else {
98- logger . error ( "Auth API Error" , "An unknown error occurred" , {
99- error,
100- ...( ctx as Record < string , unknown > ) ,
101- } ) ;
102- }
72+ onError : ( error ) => {
73+ console . error ( error ) ;
10374 } ,
10475 errorURL : "/auth/error" ,
10576 } ,
@@ -153,10 +124,6 @@ export const auth = betterAuth({
153124 user : any ;
154125 url : string ;
155126 } ) => {
156- logger . info (
157- "Email Verification" ,
158- `Sending verification email to ${ user . email } `
159- ) ;
160127 const resend = new Resend ( process . env . RESEND_API_KEY as string ) ;
161128 await resend . emails . send ( {
162129@@ -190,8 +157,7 @@ export const auth = betterAuth({
190157 } ,
191158 plugins : [
192159 emailOTP ( {
193- async sendVerificationOTP ( { email, otp, type } ) {
194- logger . info ( "Email OTP" , `Sending OTP to ${ email } of type ${ type } ` ) ;
160+ async sendVerificationOTP ( { email, otp } ) {
195161 const resend = new Resend ( process . env . RESEND_API_KEY as string ) ;
196162 await resend . emails . send ( {
197163@@ -203,7 +169,6 @@ export const auth = betterAuth({
203169 } ) ,
204170 magicLink ( {
205171 sendMagicLink : async ( { email, url } ) => {
206- logger . info ( "Magic Link" , `Sending magic link to ${ email } ` ) ;
207172 const resend = new Resend ( process . env . RESEND_API_KEY as string ) ;
208173 await resend . emails . send ( {
209174@@ -247,11 +212,6 @@ export const auth = betterAuth({
247212 organization,
248213 invitation,
249214 } ) => {
250- logger . info (
251- "Organization Invitation" ,
252- `Inviting ${ email } to ${ organization . name } ` ,
253- { inviter : inviter . user . name , organizationId : organization . id }
254- ) ;
255215 const invitationLink = `https://app.databuddy.cc/invitations/${ invitation . id } ` ;
256216 const resend = new Resend ( process . env . RESEND_API_KEY as string ) ;
257217 await resend . emails . send ( {
0 commit comments