Conversation
… fix query keys and a lot of small fixes Enable email verification and enqueue sending via job producer - Require email verification for email/password signups and enable send-on-sign-in. Hook better-auth's sendVerificationEmail to the new enqueueSendVerificationEmail producer so verification emails are processed asynchronously. Introduce typed job payload and robust worker handler - Change SendVerificationEmailPayload to include a nested user object (id, email, name) to carry user details instead of separate fields. - Wrap sendEmail call in try/catch and rethrow errors to surface job failures to the worker/pg-boss retry mechanism. Split pg-boss client roles and lifecycle management - Replace single boss with separate producerClient and workerClient. - Add getQueueClient() for lightweight enqueueing in the main app process and initQueueWorker() to start a worker and register jobs. - Add shutdownQueue() to gracefully stop clients on process exit. - Add runtime checks for DATABASE_URL and improved error logging. Misc - Add import of enqueueSendVerificationEmail in auth integration. - Adjust logging messages to clarify producer vs worker startup.
Greptile SummaryThis PR adds email verification for new signups and restructures the pg-boss queue architecture for better scalability and separation of concerns. Key changes:
Issues found:
Architecture improvements:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant SignUpForm
participant AuthClient
participant BetterAuth
participant EmailProducer
participant PgBoss
participant Worker
participant EmailJob
participant UseSend
User->>SignUpForm: Submit signup form
SignUpForm->>AuthClient: signUp.email()
AuthClient->>BetterAuth: Create user account
BetterAuth->>BetterAuth: Check requireEmailVerification=true
BetterAuth->>EmailProducer: sendVerificationEmail hook
EmailProducer->>PgBoss: getQueueClient()
PgBoss-->>EmailProducer: Return producer client
EmailProducer->>PgBoss: send(SEND_VERIFICATION_EMAIL, payload)
PgBoss-->>EmailProducer: Job enqueued
EmailProducer-->>BetterAuth: Job queued
BetterAuth-->>AuthClient: User created
AuthClient-->>SignUpForm: Success
SignUpForm->>SignUpForm: removeQueries(session)
SignUpForm->>User: Navigate to /auth/verify-email
Note over Worker,EmailJob: Separate worker process
Worker->>PgBoss: Poll for jobs
PgBoss-->>Worker: Return SEND_VERIFICATION_EMAIL job
Worker->>EmailJob: Execute job handler
EmailJob->>EmailJob: Validate payload schema
EmailJob->>UseSend: sendEmail()
UseSend-->>EmailJob: Email sent
EmailJob-->>Worker: Return success
Worker->>PgBoss: Mark job complete
|
There was a problem hiding this comment.
Additional Comments (1)
-
src/lib/server/env.ts, line 8-9 (link)logic:
USESEND_FROM_EMAILandUSESEND_BASE_URLused in send-email.ts and use-send.ts but not defined in env schema
13 files reviewed, 2 comments
Comment on lines
+47
to
+48
| } catch (error) { | ||
| throw new Error((error as Error).message); |
There was a problem hiding this comment.
style: Wrapping error loses stack trace - just rethrow the original error
Suggested change
| } catch (error) { | |
| throw new Error((error as Error).message); | |
| } catch (error) { | |
| throw error; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/features/jobs/definitions/email.job.tsx
Line: 47:48
Comment:
**style:** Wrapping error loses stack trace - just rethrow the original error
```suggestion
} catch (error) {
throw error;
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable email verification and enqueue sending via job producer
send-on-sign-in. Hook better-auth's sendVerificationEmail to the
new enqueueSendVerificationEmail producer so verification emails
are processed asynchronously.
Introduce typed job payload and robust worker handler
(id, email, name) to carry user details instead of separate fields.
failures to the worker/pg-boss retry mechanism.
Split pg-boss client roles and lifecycle management
process and initQueueWorker() to start a worker and register jobs.
Misc