@@ -38,7 +38,7 @@ export async function register({
3838 . where ( 'email_verified' , true )
3939 . orWhere ( 'email_verification_expiration_date' , '>' , new Date ( ) ) ,
4040 )
41- . select ( 'email_verified' )
41+ . select ( 'email_verified' , 'email_verification_code' )
4242 . first ( ) ;
4343
4444 // Check if user already exists
@@ -52,9 +52,14 @@ export async function register({
5252 code : 'CONFLICT' ,
5353 } ) ;
5454 } else {
55+ await sendRegistrationEmail ( {
56+ email : input . email ,
57+ emailVerificationCode : user . email_verification_code ,
58+ } ) ;
59+
5560 throw new TRPCError ( {
56- message : 'Email awaiting verification.' ,
57- code : 'CONFLICT ' ,
61+ message : 'Email awaiting verification. New email sent. ' ,
62+ code : 'UNAUTHORIZED ' ,
5863 } ) ;
5964 }
6065 }
@@ -74,18 +79,28 @@ export async function register({
7479
7580 // Send email
7681
77- await sendMail ( {
78- from : {
79- name : 'DeepNotes' ,
80- email : 'account@deepnotes.app' ,
81- } ,
82- to : [ input . email ] ,
83- subject : 'Complete your registration' ,
84- html : `
85- Visit the following link to verify your email address:<br/>
86- <a href="https://deepnotes.app/verify-email/${ user . email_verification_code } ">https://deepnotes.app/verify-email/${ user . email_verification_code } </a><br/>
87- The link above will expire in 1 hour.
88- ` ,
82+ await sendRegistrationEmail ( {
83+ email : input . email ,
84+ emailVerificationCode : user . email_verification_code ,
8985 } ) ;
9086 } ) ;
9187}
88+
89+ export async function sendRegistrationEmail ( input : {
90+ email : string ;
91+ emailVerificationCode : string | null ;
92+ } ) {
93+ await sendMail ( {
94+ from : {
95+ name : 'DeepNotes' ,
96+ email : 'account@deepnotes.app' ,
97+ } ,
98+ to : [ input . email ] ,
99+ subject : 'Complete your registration' ,
100+ html : `
101+ Visit the following link to verify your email address:<br/>
102+ <a href="https://deepnotes.app/verify-email/${ input . emailVerificationCode } ">https://deepnotes.app/verify-email/${ input . emailVerificationCode } </a><br/>
103+ The link above expires in 1 hour.
104+ ` ,
105+ } ) ;
106+ }
0 commit comments