Skip to content

Commit 263fd56

Browse files
committed
fix: verifyEmail to not delete guest contributors
Also, enforce profile completion for guests
1 parent 5a031f8 commit 263fd56

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

server/controllers/users.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,19 @@ export async function signup(req: express.Request, res: express.Response) {
263263
}
264264

265265
// Check if Users exists
266-
let user = await models.User.findOne({ where: { email: sanitizedEmail } });
266+
let user = await models.User.findOne({
267+
where: { email: sanitizedEmail },
268+
include: [{ model: models.Collective, as: 'collective' }],
269+
});
267270
if (user) {
268271
if (user.confirmedAt) {
269272
res.status(403).send({
270273
error: { message: 'User already exists', type: 'USER_ALREADY_EXISTS' },
271274
});
272275
return;
273276
}
277+
const newData = Object.assign({}, user.collective.data, { requiresProfileCompletion: true });
278+
await user.collective.update({ data: newData });
274279
} else {
275280
user = await sequelize.transaction(async transaction => {
276281
const user = await models.User.create(
@@ -473,7 +478,11 @@ export async function verifyEmail(req: express.Request, res: express.Response) {
473478
const tries = otpSession.tries + 1;
474479
if (tries >= 3) {
475480
await sessionCache.delete(otpSessionKey);
476-
await user.safeDestroy();
481+
const userHasTransactions = await user.collective.getTransactions({ limit: 1 });
482+
// Covers edge-case where the user has previously contributed as guest
483+
if (userHasTransactions.length === 0) {
484+
await user.safeDestroy();
485+
}
477486
} else {
478487
await sessionCache.set(otpSessionKey, { ...otpSession, tries }, 15 * 60);
479488
}

server/lib/guest-accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const getOrCreateGuestProfile = async (
7777
slug: `guest-${uuid().split('-')[0]}`,
7878
name: name || DEFAULT_GUEST_NAME,
7979
legalName,
80-
data: { isGuest: true },
80+
data: { isGuest: true, requiresProfileCompletion: true },
8181
CreatedByUserId: user.id,
8282
location,
8383
currency,

0 commit comments

Comments
 (0)