Emails not allowed as usernames

I have been using emails as the main username for simplicity:

    const client = new JsonServiceClient(environment.apiUrl);
    let req = new Register();
    
    req.email = this.registerForm.get("email").value;
    req.userName = req.email;
    req.firstName = this.registerForm.get("name").value;
    req.password = this.registerForm.get("password").value;

    let response = await client.post(req);

This used to work as long as the email didn’t contain a + symbol. It seems now after updating to 5.4 every email is rejected as a username for having invalid characters.

Is there any way to have the users email address as their username and support all characters that are valid in email? Do I have to make my own Register implementation or is this already available functionality?

This hasn’t changed, the Email should only be populated in the Email property, then leave the UserName empty and you’ll be able to authenticate with the Email/Password.

OK, I didn’t realise this was possible. If I don’t pass the username field it returns error that username cannot be blank but I just tried passing empty string and this actually works. Thanks.

Actually it only worked the first time, second time I get: User '' already exists

const client = new JsonServiceClient(environment.apiUrl);
let req = new Register();

req.email = this.registerForm.get("email").value;
req.userName = "";
req.firstName = this.registerForm.get("name").value;
req.password = this.registerForm.get("password").value;

let response = await client.post(req);

How do I do typescript request with blank username?

The Register forms of http://mvc.netcore.io, http://mvc.servicestack.net, GitHub - ServiceStackApps/HttpBenchmarks: A HTTP Apache Benchmarks analyzer and exporter etc. all register using Email and no UserName

Username should just be unset, not an empty string.

You must think I am crazy but I did that before and it gave error username must be supplied but now I just tried it and it worked. No idea what is going on, I think I am under attack by gremlins.

1 Like