Skip to content

fix: auth providers generate unique username on conflict#23853

Merged
Adzouz merged 6 commits intostrapi:developfrom
ndinevski:fix/auth-providers-creating-duplicate-username-entries
Apr 17, 2026
Merged

fix: auth providers generate unique username on conflict#23853
Adzouz merged 6 commits intostrapi:developfrom
ndinevski:fix/auth-providers-creating-duplicate-username-entries

Conversation

@ndinevski
Copy link
Copy Markdown
Contributor

@ndinevski ndinevski commented Jul 1, 2025

What does it do?

This change appends a number at the end of a username if the username generated from the PROVIDER email is already taken instead of making a duplicate username.

Why is it needed?

fix #23852

This change is motivated by a bug I incountered in my application. Registering normally, with a username joe, after which trying to register with joe@gmail.com or any other provider, due to the current handling of usernames, allowed the user to be created with the username joe again. Leaving us with 2 users with the same username. This is a breaking issue, that needs to be looked at. I think it is best to append a counter at the end of an already taken username in these scenarios. Initially register joe would still stay. Newly registered with provider, joe@gmail.com will get the username joe1 instead of the duplicate joe, which fixes the issue.

How to test it?

Register using a username that you have a username on any provider with, ex. joe and you have an email ex. joe@random.com. It is important not to use the google account here and use a different email. After this user any auth provider login/register, and register with the provider account ex. joe@google.com. A user with username joe1 will be created, instead of the duplicate joe. Therefore fixing the issue.

@vercel
Copy link
Copy Markdown

vercel bot commented Jul 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
contributor-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 8:56pm

@ndinevski ndinevski changed the title [FIX #23852] Auth providers create duplicate username entries if username is already registered before fix: auth providers create duplicate username entries if username is already registered before Jul 1, 2025
@hanpaine hanpaine added the community Changes and fixes created by community members label Sep 8, 2025
Comment thread packages/plugins/users-permissions/server/services/providers.js Outdated
@vercel
Copy link
Copy Markdown

vercel bot commented Dec 19, 2025

@ndinevski is attempting to deploy a commit to the Strapi Team on Vercel.

A member of the Team first needs to authorize it.

@innerdvations innerdvations self-requested a review February 5, 2026 17:07
@innerdvations innerdvations added source: plugin:users-permissions Source is plugin/users-permissions package pr: fix This PR is fixing a bug labels Feb 5, 2026
@innerdvations innerdvations changed the title fix: auth providers create duplicate username entries if username is already registered before fix: auth providers generate unique username on conflict Feb 6, 2026
Comment thread packages/plugins/users-permissions/server/services/providers.js Outdated
Comment thread packages/plugins/users-permissions/server/utils/index.js Outdated
@Adzouz Adzouz force-pushed the fix/auth-providers-creating-duplicate-username-entries branch from 0decaac to a3c2109 Compare April 16, 2026 13:04
@Adzouz Adzouz self-assigned this Apr 16, 2026
@Adzouz Adzouz added this to the 5.43.0 milestone Apr 16, 2026
@Adzouz
Copy link
Copy Markdown
Contributor

Adzouz commented Apr 16, 2026

Hey @innerdvations, I added some tests and the code looks good to me, all subjects were addressed. Do you think we can move forward and merge? (I'll run the piplelines)

@Adzouz Adzouz force-pushed the fix/auth-providers-creating-duplicate-username-entries branch from a3c2109 to 1048259 Compare April 16, 2026 13:09
@innerdvations
Copy link
Copy Markdown
Contributor

I haven't had a chance to review this again, but as long as the previous comment about using the same default values as before is addressed, that was my only blocker :)

Copy link
Copy Markdown
Contributor

@Adzouz Adzouz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it 🚀 Thanks a lot @ndinevski and sorry for the delay 🙏

@Adzouz Adzouz merged commit 7ec0f66 into strapi:develop Apr 17, 2026
180 of 184 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members pr: fix This PR is fixing a bug source: plugin:users-permissions Source is plugin/users-permissions package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth providers create duplicate username entries if username is already registered before

4 participants