Next Auth unique Username with Social Login, best approach?

I am fairly new to Next Auth, I am struggling to find the best approach here. I am requiring users to register with a username, email, and password. With the social providers, when a user authorizes (lets say their github) for the first time, the user that is created seems to be storing null for the username. This presents an issue, in my schema I have this outlined for the user: username String? @unique So if there are multiple users signing up using socials, multiple accounts will have this username of null which will throw an error when they are trying to sign up with social (since it thinks a username with "null" already exists). To fix this, I believe I could add a @default(uuid()) at the end of the schema property, but the ideal solution would be to direct the user using a social login (to register) and have them create a unique username. How would you normally approach this?
2 Replies
Aland
Aland13mo ago
I would first remove white spaces from their name and set it as their username, so Aland Sleman > AlandSleman If there is no name, then i would just generate a unique username.
Lopen
Lopen13mo ago
First, check the first+last name exists as username. If it does, then join the users' first name and last name together, then add random 4 numbers at the end First name = david Last name = John Example one Username = davidjohn Example two Username = davidjohn2683 Also before adding it confirm the username doesn't exist