Spaces:
Running
Running
axeronis commited on
Commit ·
1f5dbf6
1
Parent(s): b4bf023
feat: add PATCH /auth/me endpoint for updating user name
Browse files
backend/app/api/auth.py
CHANGED
|
@@ -94,6 +94,11 @@ class ChangePasswordRequest(BaseModel):
|
|
| 94 |
new_password: str
|
| 95 |
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# ============================================================================
|
| 98 |
# Auth Endpoints
|
| 99 |
# ============================================================================
|
|
@@ -358,6 +363,41 @@ async def get_me(
|
|
| 358 |
)
|
| 359 |
|
| 360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
@router.post("/google", response_model=TokenResponse)
|
| 362 |
async def google_auth(
|
| 363 |
request: GoogleAuthRequest,
|
|
|
|
| 94 |
new_password: str
|
| 95 |
|
| 96 |
|
| 97 |
+
class UpdateProfileRequest(BaseModel):
|
| 98 |
+
full_name: Optional[str] = None
|
| 99 |
+
# avatar_url will be handled separately via file upload
|
| 100 |
+
|
| 101 |
+
|
| 102 |
# ============================================================================
|
| 103 |
# Auth Endpoints
|
| 104 |
# ============================================================================
|
|
|
|
| 363 |
)
|
| 364 |
|
| 365 |
|
| 366 |
+
@router.patch("/me", response_model=UserResponse)
|
| 367 |
+
async def update_me(
|
| 368 |
+
body: UpdateProfileRequest,
|
| 369 |
+
current_user: User = Depends(get_current_user),
|
| 370 |
+
session: AsyncSession = Depends(get_async_session)
|
| 371 |
+
):
|
| 372 |
+
"""
|
| 373 |
+
Update current user profile (full_name).
|
| 374 |
+
"""
|
| 375 |
+
# Update fields if provided
|
| 376 |
+
if body.full_name is not None:
|
| 377 |
+
current_user.full_name = body.full_name
|
| 378 |
+
|
| 379 |
+
session.add(current_user)
|
| 380 |
+
await session.commit()
|
| 381 |
+
await session.refresh(current_user)
|
| 382 |
+
|
| 383 |
+
# Get tenant info for response
|
| 384 |
+
result = await session.execute(
|
| 385 |
+
select(Tenant).where(Tenant.id == current_user.tenant_id)
|
| 386 |
+
)
|
| 387 |
+
tenant = result.scalar_one_or_none()
|
| 388 |
+
|
| 389 |
+
return UserResponse(
|
| 390 |
+
id=current_user.id,
|
| 391 |
+
email=current_user.email,
|
| 392 |
+
full_name=current_user.full_name,
|
| 393 |
+
tenant_id=current_user.tenant_id,
|
| 394 |
+
tenant_name=tenant.name if tenant else "Unknown",
|
| 395 |
+
is_active=current_user.is_active,
|
| 396 |
+
is_superuser=current_user.is_superuser,
|
| 397 |
+
role=current_user.role
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
|
| 401 |
@router.post("/google", response_model=TokenResponse)
|
| 402 |
async def google_auth(
|
| 403 |
request: GoogleAuthRequest,
|
frontend/app/settings/account/page.tsx
CHANGED
|
@@ -89,13 +89,20 @@ export default function AccountSettingsPage() {
|
|
| 89 |
}
|
| 90 |
}, [tenantData, user])
|
| 91 |
|
| 92 |
-
// Save profile (company name)
|
| 93 |
const handleSaveProfile = async () => {
|
| 94 |
setSavingProfile(true)
|
| 95 |
try {
|
|
|
|
| 96 |
await api.patch('/api/v1/tenants/me', {
|
| 97 |
company_name: formData.company_name
|
| 98 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
queryClient.invalidateQueries({ queryKey: ['tenant-profile'] })
|
| 100 |
toast.success('Успех!', 'Профиль сохранён')
|
| 101 |
} catch {
|
|
|
|
| 89 |
}
|
| 90 |
}, [tenantData, user])
|
| 91 |
|
| 92 |
+
// Save profile (company name + user name)
|
| 93 |
const handleSaveProfile = async () => {
|
| 94 |
setSavingProfile(true)
|
| 95 |
try {
|
| 96 |
+
// Update tenant (company name)
|
| 97 |
await api.patch('/api/v1/tenants/me', {
|
| 98 |
company_name: formData.company_name
|
| 99 |
})
|
| 100 |
+
|
| 101 |
+
// Update user (full_name)
|
| 102 |
+
await api.patch('/api/v1/auth/me', {
|
| 103 |
+
full_name: formData.full_name
|
| 104 |
+
})
|
| 105 |
+
|
| 106 |
queryClient.invalidateQueries({ queryKey: ['tenant-profile'] })
|
| 107 |
toast.success('Успех!', 'Профиль сохранён')
|
| 108 |
} catch {
|