Hi Community,
Regarding creation of new end-users, all along i was under the impression that we can't create duplicate user names, but same email address is fine.
However, earlier when i was trying out some other logic (actually to see if username is case-sensitive), i was able to create duplicate records in my personal environment.
After exploring,
Want to do a quick check, if anybody is facing this too.
Thanks!
Hi Jun Mun Chan,If you are using CRUD operations CreateUser or CreateOrUpdateUser from User Entity directly and you are planning to avoid duplicate usernames, you should do perform Custom server side validation to check whether the username is already exist or not. I suggest you do;Call an aggregate before CreateOrUpdateUser and filter to get if any duplicate username exists in the User Entity. Then, call an if condition under the aggregate(put the max record of aggregate as 1). Check whether the Aggregate is empty or not. If it's empty, you can proceed to CreateOrUpdateUser, otherwise, throw an exception saying "Username already exists" or a similar message.
In the case of the User_CreateOrUpdate server action from the Users module, it already have the validation inside itThanks
Thanks, had just literally tried the User_CreateOrUpdate to check whether the validation is inside.
It is.
Actually, i do have some validations done up already. The above behavior is something i accidentally discover when testing out other things.
Oh ok then, your approach is correct. Since the User table does not have a unique index for the Username, need to perform a custom server-side validation to check for duplicates before inserting or updating a record.
I think as long as i use the provided server actions from the users module (User_Create or User_CreateOrUpdate) in my logic, and NOT the CRUD directly from the entity table, Outsystems will help me check for duplicate username. It is the duplicate email address, which i need to have a custom validation.
Cause the end user could make a typo on the username, but keys in a duplicate email address. So it is this scenario which i need to surface out to them.
Of course, if they really make a typo on both username and email, there is nothing i can do too