Fixed new user username formating
This commit is contained in:
@@ -123,9 +123,14 @@ export const CreateUserModal: React.FC<CreateUserModalProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
const rawEmail = values.email.trim().toLowerCase();
|
||||
const sanitizedUserName = values.userName?.trim()
|
||||
? values.userName.trim().toLowerCase().replace(/\s+/g, '.').replace(/[^a-z0-9_.\-@+]/g, '')
|
||||
: rawEmail.split('@')[0];
|
||||
|
||||
const payload: CreateUserRequest = {
|
||||
email: values.email.trim(),
|
||||
userName: values.userName?.trim() || values.email.split('@')[0],
|
||||
email: rawEmail,
|
||||
userName: sanitizedUserName || rawEmail,
|
||||
emailConfirmed: true,
|
||||
phoneNumber: values.phoneNumber?.trim() || null,
|
||||
phoneNumberConfirmed: false,
|
||||
|
||||
@@ -293,9 +293,14 @@ export const GovernancePage: React.FC = () => {
|
||||
setIsSubmittingQuickUser(true);
|
||||
try {
|
||||
const tenantId = getCurrentUserTenantId() || 1;
|
||||
const rawEmail = quickUserEmail.trim().toLowerCase();
|
||||
const sanitizedUserName = quickUserName.trim()
|
||||
? quickUserName.trim().toLowerCase().replace(/\s+/g, '.').replace(/[^a-z0-9_.\-@+]/g, '')
|
||||
: rawEmail.split('@')[0];
|
||||
|
||||
const payload: CreateUserRequest = {
|
||||
email: quickUserEmail.trim().toLowerCase(),
|
||||
userName: quickUserName.trim() || quickUserEmail.split('@')[0],
|
||||
email: rawEmail,
|
||||
userName: sanitizedUserName || rawEmail,
|
||||
emailConfirmed: true,
|
||||
phoneNumber: quickUserPhone.trim() || null,
|
||||
phoneNumberConfirmed: false,
|
||||
@@ -1666,14 +1671,15 @@ export const GovernancePage: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[11px] font-medium text-slate-300 mb-1">Full / User Name</label>
|
||||
<label className="block text-[11px] font-medium text-slate-300 mb-1">Full Name / Username</label>
|
||||
<input
|
||||
type="text"
|
||||
value={quickUserName}
|
||||
onChange={(e) => setQuickUserName(e.target.value)}
|
||||
placeholder="e.g. Sipho Ndlovu"
|
||||
placeholder="e.g. Tony Ngcobo"
|
||||
className="w-full px-2.5 py-1.5 text-xs border border-slate-700/80 rounded-lg bg-[#090d16] text-white focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
/>
|
||||
<p className="text-[10px] text-slate-500 mt-0.5">Will be normalized to valid login username (e.g. tony.ngcobo)</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -1382,10 +1382,22 @@ export const createUser = async (
|
||||
): Promise<void> => {
|
||||
const encodedTenant = encodeEntityId(tenantId) || String(tenantId);
|
||||
const encodedIdNumber = encodeIdNumberHex(idNumber);
|
||||
|
||||
// Normalize and sanitize userName: Duende / Skoruba Identity Server rejects usernames with spaces
|
||||
const rawEmail = payload.email?.trim().toLowerCase() || '';
|
||||
const rawUserName = payload.userName?.trim();
|
||||
let sanitizedUserName = rawUserName
|
||||
? rawUserName.toLowerCase().replace(/\s+/g, '.').replace(/[^a-z0-9_.\-@+]/g, '')
|
||||
: rawEmail.split('@')[0];
|
||||
|
||||
if (!sanitizedUserName) {
|
||||
sanitizedUserName = rawEmail;
|
||||
}
|
||||
|
||||
await apiClient.post(`/v1/api/users/${encodeURIComponent(encodedTenant)}/${encodeURIComponent(encodedIdNumber)}`, {
|
||||
id: payload.id || null,
|
||||
userName: payload.userName || null,
|
||||
email: payload.email || null,
|
||||
userName: sanitizedUserName,
|
||||
email: rawEmail || null,
|
||||
emailConfirmed: payload.emailConfirmed ?? true,
|
||||
phoneNumber: payload.phoneNumber || null,
|
||||
phoneNumberConfirmed: payload.phoneNumberConfirmed ?? false,
|
||||
|
||||
Reference in New Issue
Block a user