Skip to content

Commit 04b2353

Browse files
fix: ensure that the welcome email is sent if the callback runs on the same day a human was added (#24)
* fix: ensure that the welcome email is sent if the callback runs on the same day a human was added * format
1 parent 618a374 commit 04b2353

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/app/auth/callback/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function GET(req: Request) {
4949
: null;
5050

5151
const human = await db().human(user.data.id);
52-
if (!human)
52+
if (!human) {
5353
await db().createUser({
5454
githubId: user.data.id,
5555
username: user.data.login,
@@ -62,11 +62,13 @@ export async function GET(req: Request) {
6262
bio: user.data.bio,
6363
location: user.data.location,
6464
});
65+
}
6566

6667
await welcome({
6768
githubId: user.data.id,
6869
email: primaryEmail,
6970
name: user.data.name,
71+
createdAt: human?.createdAt as Date,
7072
});
7173

7274
const cookieStore = await cookies();

src/lib/server/email.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ const SUBJECTS = [
5555
'Congrats — you’ve leveled up in pettiness 🎖️',
5656
];
5757

58-
export async function welcome(user: Pick<User, 'githubId' | 'email' | 'name'>) {
58+
export async function welcome(
59+
user: Pick<User, 'createdAt' | 'githubId' | 'email' | 'name'>
60+
) {
5961
const human = await db().human(user.githubId);
60-
if (human) return;
62+
if (new Date(human?.createdAt as Date).getDate() !== new Date().getDate())
63+
return;
6164

6265
const domain =
6366
NODE_ENV === 'production' ? EMAIL_DOMAIN : '[email protected]';

0 commit comments

Comments
 (0)