@@ -300,6 +300,47 @@ router.get('/verify-email', async (req, res) => {
300300 }
301301} ) ;
302302
303+ router . post ( '/resend-verification' , async ( req , res ) => {
304+ try {
305+ const { email } = req . body ;
306+ if ( ! email || typeof email !== 'string' ) {
307+ return res . status ( 400 ) . json ( { error : 'Email is required' } ) ;
308+ }
309+
310+ const users = await query ( 'SELECT id, email, username, email_verified FROM users WHERE email = ?' , [ email ] ) ;
311+ if ( users . length === 0 ) {
312+ return res . json ( { message : 'If an account with that email exists, a verification link has been sent.' } ) ;
313+ }
314+
315+ const user = users [ 0 ] ;
316+ if ( user . email_verified ) {
317+ return res . json ( { message : 'Email already verified. You can now sign in.' } ) ;
318+ }
319+
320+ const verificationToken = randomBytes ( 32 ) . toString ( 'hex' ) ;
321+ const tokenExpires = new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 ) ;
322+
323+ await query (
324+ 'UPDATE users SET verification_token = ?, verification_token_expires = ? WHERE id = ?' ,
325+ [ verificationToken , tokenExpires , user . id ]
326+ ) ;
327+
328+ try {
329+ await sendVerificationEmail ( user . email , user . username , verificationToken ) ;
330+ } catch ( err ) {
331+ console . error ( 'Failed to send verification email:' , err . message ) ;
332+ return res . status ( 500 ) . json ( { error : 'Failed to send verification email. Please try again later.' } ) ;
333+ }
334+
335+ await logActivity ( user . id , 'verification_resent' , 'Resent verification email' ) ;
336+
337+ res . json ( { message : 'Verification email sent. Check your inbox.' } ) ;
338+ } catch ( err ) {
339+ console . error ( 'Resend verification error:' , err . message ) ;
340+ res . status ( 500 ) . json ( { error : 'Failed to resend verification email' } ) ;
341+ }
342+ } ) ;
343+
303344router . post ( '/login' , async ( req , res ) => {
304345 try {
305346 const { email, password, capToken } = req . body ;
0 commit comments