Skip to content

Commit

Permalink
[feat] prefer name over email substring
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-dalby committed Jan 5, 2025
1 parent 8adc608 commit 76a1229
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions server/src/repositories/userRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,17 @@ class UserRepository {
const user = this.findByOIDCIdStmt.get(profile.sub, provider);
if (user) return user;

const baseUsername = profile.email?.split('@')[0] ||
profile.preferred_username ||
profile.sub;
const sanitizeName = (name) => {
return name
.toLowerCase()
.replace(/[^a-z0-9]/g, '')
.slice(0, 30);
};

let baseUsername = profile.name ? sanitizeName(profile.name) :
profile.preferred_username ? sanitizeName(profile.preferred_username) :
profile.email?.split('@')[0] ||
profile.sub;

const username = await this.generateUniqueUsername(baseUsername);

Expand Down

0 comments on commit 76a1229

Please sign in to comment.