fix: auto-derive org domains from member emails; keep domain validation on backend
This commit is contained in:
parent
5c17bf5980
commit
8b0a09bb7e
|
|
@ -1299,8 +1299,11 @@ func (h *Handlers) CreateOrg(w http.ResponseWriter, r *http.Request) {
|
||||||
ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required")
|
ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Domains are optional — used for invite validation only
|
if len(req.Domains) == 0 {
|
||||||
// Validate domains are not empty strings (if provided)
|
ErrorResponse(w, http.StatusBadRequest, "missing_fields", "At least one domain required")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Validate domains are not empty strings
|
||||||
for _, d := range req.Domains {
|
for _, d := range req.Domains {
|
||||||
if strings.TrimSpace(d) == "" {
|
if strings.TrimSpace(d) == "" {
|
||||||
ErrorResponse(w, http.StatusBadRequest, "invalid_domains", "Empty domain not allowed")
|
ErrorResponse(w, http.StatusBadRequest, "invalid_domains", "Empty domain not allowed")
|
||||||
|
|
|
||||||
|
|
@ -1057,8 +1057,11 @@
|
||||||
try {
|
try {
|
||||||
let orgId = existingOrgId;
|
let orgId = existingOrgId;
|
||||||
if (!orgId) {
|
if (!orgId) {
|
||||||
// Create new global org first
|
// Auto-derive domains from member emails
|
||||||
const createRes = await fetchAPI('/api/orgs', { method: 'POST', body: JSON.stringify({ name, domains: [], role, website: '' }) });
|
const emailDomains = [...new Set(
|
||||||
|
members.map(m => m.email ? m.email.split('@')[1] : null).filter(Boolean)
|
||||||
|
)];
|
||||||
|
const createRes = await fetchAPI('/api/orgs', { method: 'POST', body: JSON.stringify({ name, domains: emailDomains, role, website: '' }) });
|
||||||
if (!createRes.ok) { const e = await createRes.json(); throw new Error(e.error || 'Failed to create org'); }
|
if (!createRes.ok) { const e = await createRes.json(); throw new Error(e.error || 'Failed to create org'); }
|
||||||
const created = await createRes.json();
|
const created = await createRes.json();
|
||||||
orgId = created.entry_id || created.org_id;
|
orgId = created.entry_id || created.org_id;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue