Skip to content

Commit

Permalink
fix(core): should not sync registered identifier from social
Browse files Browse the repository at this point in the history
should not sync registered identifier from social
  • Loading branch information
simeng-li committed Jul 19, 2024
1 parent 34b57c8 commit f1736ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,15 @@ export class SocialVerification implements IdentifierVerificationRecord<Verifica
const { name, avatar, email: primaryEmail, phone: primaryPhone } = this.socialUserInfo;

if (isNewUser) {
const {
users: { hasUserWithEmail, hasUserWithPhone },
} = this.queries;

Check warning on line 216 in packages/core/src/routes/experience/classes/verifications/social-verification.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/routes/experience/classes/verifications/social-verification.ts#L213-L216

Added lines #L213 - L216 were not covered by tests
return {
...conditional(primaryEmail && { primaryEmail }),
...conditional(primaryPhone && { primaryPhone }),
// Sync the email only if the email is not used by other users
...conditional(primaryEmail && !(await hasUserWithEmail(primaryEmail)) && { primaryEmail }),
// Sync the phone only if the phone is not used by other users
...conditional(primaryPhone && !(await hasUserWithPhone(primaryPhone)) && { primaryPhone }),

Check warning on line 221 in packages/core/src/routes/experience/classes/verifications/social-verification.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/routes/experience/classes/verifications/social-verification.ts#L218-L221

Added lines #L218 - L221 were not covered by tests
...conditional(name && { name }),
...conditional(avatar && { avatar }),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ devFeatureTest.describe('social sign-in and sign-up', () => {
expect(primaryEmail).toBe(email);
});

it('should successfully sign-up with social but not sync email if the email is registered by another user', async () => {
const { userProfile, user } = await generateNewUser({
primaryEmail: true,
});

const { primaryEmail } = userProfile;

const userId = await signInWithSocial(
connectorIdMap.get(mockSocialConnectorId)!,
{
id: generateStandardId(),
email: primaryEmail,
},
{
registerNewUser: true,
}
);

expect(userId).not.toBe(user.id);
const { primaryEmail: newUserPrimaryEmail } = await getUser(userId);
expect(newUserPrimaryEmail).toBeNull();

await Promise.all([deleteUser(userId), deleteUser(user.id)]);
});

it('should successfully sign-in with social and sync name', async () => {
const userId = await signInWithSocial(connectorIdMap.get(mockSocialConnectorId)!, {
id: socialUserId,
Expand Down

0 comments on commit f1736ad

Please sign in to comment.