Skip to content

Commit

Permalink
Refactor welcome email trigger location
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HugoRCD committed Nov 3, 2024
1 parent 0d680e5 commit db67f4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion apps/shelve/server/routes/auth/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions apps/shelve/server/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { publicUser, User, CreateUserInput, UpdateUserInput } from '@shelve/types'
import { EmailService } from '~~/server/services/resend.service'

export class UserService {

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit db67f4c

Please sign in to comment.