File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,24 +113,29 @@ export async function handleGoldenTicket(email: string) {
113113 return { success : false , error : 'Unauthorized' } ;
114114 }
115115
116- await db . transaction ( async ( tx ) => {
117- await tx . insert ( earlyAccess ) . values ( {
116+ await db
117+ . insert ( earlyAccess )
118+ . values ( {
118119 id : crypto . randomUUID ( ) ,
119120 email,
120121 createdAt : new Date ( ) ,
121122 updatedAt : new Date ( ) ,
122123 isEarlyAccess : true ,
123124 hasUsedTicket : '' ,
124- } ) . catch ( ( ) => {
125- console . log ( 'Failed to insert early access record, updating user still' ) ;
126- } ) ;
127- await tx . update ( earlyAccess )
128- . set ( {
129- hasUsedTicket : email ,
130- updatedAt : new Date ( )
131- } )
132- . where ( eq ( earlyAccess . email , foundUser . email ) ) ;
133- } ) ;
125+ } ) . catch ( ( error ) => {
126+ console . log ( 'Error registering early access' , error ) ;
127+ if ( error . code === '23505' ) {
128+ console . log ( 'Email already registered for early access, granted access' ) ;
129+ } else {
130+ console . error ( 'Error registering early access' , error ) ;
131+ throw error ;
132+ }
133+ } )
134+
135+ await db . update ( earlyAccess ) . set ( {
136+ hasUsedTicket : email ,
137+ updatedAt : new Date ( )
138+ } ) . where ( eq ( earlyAccess . email , foundUser ?. email ) )
134139
135140 return { success : true } ;
136141 } catch ( error ) {
You can’t perform that action at this time.
0 commit comments