fix(username): sign in should work with post normalization (#4599)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
Bereket Engida
2025-09-11 17:49:10 -07:00
committed by GitHub
parent 8df46e6336
commit b2dfbc96b4
2 changed files with 28 additions and 2 deletions

View File

@@ -264,13 +264,13 @@ export const username = (options?: UsernameOptions) => {
}
const user = await ctx.context.adapter.findOne<
User & { username: string }
User & { username: string; displayUsername: string }
>({
model: "user",
where: [
{
field: "username",
value: username,
value: normalizer(username),
},
],
});
@@ -358,6 +358,7 @@ export const username = (options?: UsernameOptions) => {
email: user.email,
emailVerified: user.emailVerified,
username: user.username,
displayUsername: user.displayUsername,
name: user.name,
image: user.image,
createdAt: user.createdAt,

View File

@@ -269,6 +269,31 @@ describe("username", async (it) => {
expect(session?.user.username).toBe("custom_user");
expect(session?.user.displayUsername).toBe("Fancy Display Name");
});
it("should sign in with normalized username", async () => {
const { client } = await getTestInstance(
{
plugins: [username()],
},
{
clientOptions: {
plugins: [usernameClient()],
},
},
);
await client.signUp.email({
email: "normalized-username@email.com",
username: "Custom_User",
password: "test-password",
name: "test-name",
});
const res2 = await client.signIn.username({
username: "Custom_User",
password: "test-password",
});
expect(res2.data?.user.username).toBe("custom_user");
expect(res2.data?.user.displayUsername).toBe("Custom_User");
});
});
describe("username custom normalization", async (it) => {