Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
🤖 Auto-generated usernames always meet 6 character requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Feb 20, 2022
1 parent 24c541c commit afc030a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/EasyFirebase/Services/Auth/EasyUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ open class EasyUser: IndexedDocument {
lastSignon = Date()
self.email = email
username = email.removeDomainFromEmail()
displayName = user.displayName ?? username
if username.count < 6 {
username += String.random(length: 6 - username.count)
}
displayName = user.displayName ?? email.removeDomainFromEmail()
profileImageURL = user.photoURL?.absoluteString ?? EasyAuth.defaultProfileImageURLs.randomElement()!.absoluteString
updateAnalyticsUserProperties()
refreshEmailVerifcationStatus()
Expand Down Expand Up @@ -401,3 +404,10 @@ public extension EasyUser {
return uid == id
}
}

fileprivate extension String {
static func random(length: Int) -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
return String((0..<length).map{ _ in letters.randomElement()! })
}
}

0 comments on commit afc030a

Please sign in to comment.