Skip to content

Commit

Permalink
Set the user ID in Loops if the user is already logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta authored and JosiasAurel committed Apr 4, 2024
1 parent 11013d9 commit 98180d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions src/lib/game-saving/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ const findOrCreateEmailListContact = async (email: string): Promise<Object | und
}
}

export const addToEmailList = async (email: string, userId: string): Promise<void> => {
await findOrCreateEmailListContact(email)
await loops.updateContact(email, {
sprigEditorUserId: userId
})
const emailListAttrs = (user: User): any => {
return {
sprigEditorUserId: user.id
}
}

export const addToEmailList = async (user: User): Promise<void> => {
await findOrCreateEmailListContact(user.email)
await loops.updateContact(user.email, emailListAttrs(user))
}

export const updateEmailListLastModifiedTime = async (email: string, lastModified: Date): Promise<void> => {
await findOrCreateEmailListContact(email)
await loops.updateContact(email, {
sprigEditorGameLastModifiedAt: lastModified.getTime()
export const updateEmailListLastModifiedTime = async (user: User, lastModified: Date): Promise<void> => {
await findOrCreateEmailListContact(user.email)
await loops.updateContact(user.email, {
sprigEditorGameLastModifiedAt: lastModified.getTime(),
...emailListAttrs(user)
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/auth/email-login-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const post: APIRoute = async ({ request }) => {
const user = await getUserByEmail(email) ?? await makeUser(email, null)
const code = await makeLoginCode(user.id)
await mail(user.email, loginCodeTemplate(code))
await addToEmailList(user.email, user.id)
await addToEmailList(user)
return new Response(JSON.stringify({}), { status: 200 })
}
2 changes: 1 addition & 1 deletion src/pages/api/games/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const post: APIRoute = async ({ request, cookies }) => {
trackingId = session.user.id
trackingType = 'user'

await updateEmailListLastModifiedTime(session.user.email, new Date())
await updateEmailListLastModifiedTime(session.user, new Date())
}

await updateDocument('games', gameId, {
Expand Down

0 comments on commit 98180d8

Please sign in to comment.