From 92be5ee3d2898d167a2e73fb776b00a2961cff74 Mon Sep 17 00:00:00 2001 From: Alberto-Audrix Date: Tue, 8 Sep 2026 16:23:05 +0700 Subject: [PATCH] Wire frontend login to user_login. Co-authored-by: Cursor --- components/auth/LoginForm.tsx | 18 +++++++++--------- context/AuthContext.tsx | 6 +++--- services/apiClient.ts | 4 ++-- types/api.ts | 2 ++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/components/auth/LoginForm.tsx b/components/auth/LoginForm.tsx index 51532d3..491ad56 100644 --- a/components/auth/LoginForm.tsx +++ b/components/auth/LoginForm.tsx @@ -4,7 +4,7 @@ import { errorMessage } from '../../services/apiClient.ts'; const LoginForm: React.FC = () => { const { login } = useAuth(); - const [userName, setUserName] = useState(''); + const [userLogin, setUserLogin] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); @@ -14,7 +14,7 @@ const LoginForm: React.FC = () => { setError(''); setIsLoading(true); try { - await login(userName, password); + await login(userLogin, password); } catch (err) { setError(errorMessage(err)); } finally { @@ -30,20 +30,20 @@ const LoginForm: React.FC = () => { )}
-
diff --git a/context/AuthContext.tsx b/context/AuthContext.tsx index d6d7bd0..95b6a2f 100644 --- a/context/AuthContext.tsx +++ b/context/AuthContext.tsx @@ -5,7 +5,7 @@ import type { User } from '../types/api.ts'; type AuthContextValue = { user: User | null; loading: boolean; - login: (userName: string, password: string) => Promise; + login: (userLogin: string, password: string) => Promise; logout: () => Promise; refreshUser: () => Promise; }; @@ -45,9 +45,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }; }, []); - const login = useCallback(async (userName: string, password: string) => { + const login = useCallback(async (userLogin: string, password: string) => { await api.auth.csrf(); - const next = await api.auth.login(userName, password); + const next = await api.auth.login(userLogin, password); setUser(next); }, []); diff --git a/services/apiClient.ts b/services/apiClient.ts index 21f80a1..11d5c18 100644 --- a/services/apiClient.ts +++ b/services/apiClient.ts @@ -159,8 +159,8 @@ const del = (path: string) => request(path, { method: 'DELETE' }); export const api = { auth: { csrf: () => get<{ csrfToken: string }>('/auth/csrf/'), - login: (user_name: string, password: string) => - post('/auth/login/', { user_name, password }), + login: (user_login: string, password: string) => + post('/auth/login/', { user_login, password }), logout: () => post('/auth/logout/'), me: () => get('/auth/me/'), }, diff --git a/types/api.ts b/types/api.ts index 5a25a4b..65da121 100644 --- a/types/api.ts +++ b/types/api.ts @@ -18,6 +18,7 @@ export type UserStatus = export type User = { id: number; + user_login: string; user_name: string; status: UserStatus; is_superuser?: boolean; @@ -31,6 +32,7 @@ export type User = { }; export type UserWrite = { + user_login: string; user_name: string; status: UserStatus; password?: string;