Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): should not sync registered identifier from social #6283

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
new RequestError({ code: 'session.verification_failed', status: 400 })
);

// TODO: sync userInfo and link social identity

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[no-warning-comments] Unexpected 'todo' comment: 'TODO: sync userInfo and link social...'.

const user = await this.findUserBySocialIdentity();

Expand Down Expand Up @@ -210,9 +210,15 @@
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 () => {
simeng-li marked this conversation as resolved.
Show resolved Hide resolved
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
Loading