From db67f4c526034418039bdfc0b0188b1135699a69 Mon Sep 17 00:00:00 2001 From: HugoRCD Date: Sun, 3 Nov 2024 21:50:28 +0100 Subject: [PATCH] Refactor welcome email trigger location Moved the triggering of the welcome email from GitHub OAuth event handler to UserService. Now, the welcome email is sent when a new user is created in UserService instead of after successful GitHub authentication. This change ensures that all new users, regardless of their method of registration, receive a welcome email. --- apps/shelve/server/routes/auth/github.ts | 1 - apps/shelve/server/services/user.service.ts | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/shelve/server/routes/auth/github.ts b/apps/shelve/server/routes/auth/github.ts index 21c5a573..be165e61 100644 --- a/apps/shelve/server/routes/auth/github.ts +++ b/apps/shelve/server/routes/auth/github.ts @@ -28,7 +28,6 @@ export default defineOAuthGitHubEventHandler({ }, loggedInAt: new Date().toISOString(), }) - await emailService.sendWelcomeEmail(user.email, user.login) return sendRedirect(event, '/app/projects') } catch (error) { console.error('GitHub OAuth error:', error) diff --git a/apps/shelve/server/services/user.service.ts b/apps/shelve/server/services/user.service.ts index e4a2db8c..51d6dcab 100644 --- a/apps/shelve/server/services/user.service.ts +++ b/apps/shelve/server/services/user.service.ts @@ -1,4 +1,5 @@ import type { publicUser, User, CreateUserInput, UpdateUserInput } from '@shelve/types' +import { EmailService } from '~~/server/services/resend.service' export class UserService { @@ -30,8 +31,12 @@ export class UserService { create: { ...createUserInput, username: newUsername, - }, - }) + } + }) as User + if (user.createdAt === user.updatedAt) { + const emailService = new EmailService() + await emailService.sendWelcomeEmail(user.email, user.username) + } return this.formatUser(user) }