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,28 @@ 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+ return db . update ( earlyAccess ) . set ( {
130+ hasUsedTicket : email ,
131+ updatedAt : new Date ( )
132+ } ) . where ( eq ( earlyAccess . email , foundUser ?. email ) )
133+ } else {
134+ console . error ( 'Error registering early access' , error ) ;
135+ throw error ;
136+ }
137+ } )
134138
135139 return { success : true } ;
136140 } catch ( error ) {
You can’t perform that action at this time.
0 commit comments