diff --git a/backend/apps/web/models/auths.py b/backend/apps/web/models/auths.py index 07c751988..dfa0c4395 100644 --- a/backend/apps/web/models/auths.py +++ b/backend/apps/web/models/auths.py @@ -90,7 +90,7 @@ class SignupForm(BaseModel): class AddUserForm(SignupForm): - role: str = "pending" + role: Optional[str] = "pending" class AuthsTable: diff --git a/backend/apps/web/routers/auths.py b/backend/apps/web/routers/auths.py index e08f0ac84..e4a41a74d 100644 --- a/backend/apps/web/routers/auths.py +++ b/backend/apps/web/routers/auths.py @@ -223,14 +223,15 @@ async def signup(form_data: AddUserForm, user=Depends(get_admin_user)): raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN) try: - role = form_data.role + + print(form_data) hashed = get_password_hash(form_data.password) user = Auths.insert_new_auth( form_data.email.lower(), hashed, form_data.name, form_data.profile_image_url, - role, + form_data.role, ) if user: diff --git a/src/lib/apis/auths/index.ts b/src/lib/apis/auths/index.ts index f7c75d02d..26feb29b6 100644 --- a/src/lib/apis/auths/index.ts +++ b/src/lib/apis/auths/index.ts @@ -100,14 +100,15 @@ export const addUser = async ( name: string, email: string, password: string, - role: string + role: string = 'pending' ) => { let error = null; const res = await fetch(`${WEBUI_API_BASE_URL}/auths/add`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) }, body: JSON.stringify({ name: name, diff --git a/src/lib/components/admin/AddUserModal.svelte b/src/lib/components/admin/AddUserModal.svelte index 44d5ba238..e779c9f75 100644 --- a/src/lib/components/admin/AddUserModal.svelte +++ b/src/lib/components/admin/AddUserModal.svelte @@ -15,9 +15,18 @@ name: '', email: '', password: '', - role: '' + role: 'pending' }; + $: if (show) { + _user = { + name: '', + email: '', + password: '', + role: 'pending' + }; + } + const submitHandler = async () => { const res = await addUser( localStorage.token, @@ -38,7 +47,7 @@
-
+
{$i18n.t('Add User')}
-
+
{#if chats.length > 0}