Skip to content

Commit cad5a40

Browse files
authored
chore: Unique usermames (#76)
1 parent f2199ac commit cad5a40

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

apps/event-system/services/users/users.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import axios from 'axios';
99
import { get, omit, pick, uniqBy } from 'lodash';
1010
import DbService from 'moleculer-db';
1111
import MongoDBAdapter from 'moleculer-db-adapter-mongo';
12+
import { v4 as uuidv4 } from 'uuid';
13+
1214

1315
const Auth = require('@libs-private/service-logic/mixins/auth');
1416

@@ -429,8 +431,7 @@ module.exports = {
429431
verified: get(user, 'verified_email', false)
430432
}];
431433

432-
// Google doesn't provide username, so we'll create one from email.
433-
const username = email.split('@')[0];
434+
const username = `${email.split('@')[0]}-${uuidv4().replace(/-/g, '').substring(0, 16)}`;
434435

435436
// Google provides given_name and family_name directly
436437
const firstName = get(user, 'given_name', '');
@@ -587,7 +588,7 @@ module.exports = {
587588
)
588589
: null;
589590

590-
const username = get(user, 'login');
591+
const username = `${get(user, 'login')}-${uuidv4().replace(/-/g, '').substring(0, 16)}`;
591592

592593
const [firstName, lastName] = getFirstAndLastNameFromName(
593594
get(user, 'name')
@@ -695,7 +696,7 @@ module.exports = {
695696
},
696697
];
697698

698-
const username = get(user, 'username');
699+
const username = `${get(user, 'username')}-${uuidv4().replace(/-/g, '').substring(0, 16)}`;
699700

700701
const [firstName, lastName] = getFirstAndLastNameFromName(
701702
get(user, 'name')

0 commit comments

Comments
 (0)