Enhance authentication input fields with autocomplete attributes and refactor API registration and login methods for improved response handling

This commit is contained in:
Artem Kashaev
2026-05-28 11:33:13 +05:00
parent e48b1fc0e9
commit 2f5fd2f3d4
4 changed files with 14 additions and 9 deletions
+2 -2
View File
@@ -116,11 +116,11 @@ function AuthScreen({ onAuth }: { onAuth: (auth: AuthState) => void }) {
)}
<label>
Email
<input type="email" value={email} onChange={(event) => setEmail(event.target.value)} />
<input type="email" autoComplete="username" value={email} onChange={(event) => setEmail(event.target.value)} />
</label>
<label>
Пароль
<input type="password" value={password} onChange={(event) => setPassword(event.target.value)} />
<input type="password" autoComplete={mode === "register" ? "new-password" : "current-password"} value={password} onChange={(event) => setPassword(event.target.value)} />
</label>
{error && <p className="error">{error}</p>}
<button className="primary" disabled={mutation.isPending}>
+6 -4
View File
@@ -25,11 +25,13 @@ async function request<T>(path: string, options: RequestInit = {}, token?: strin
}
export const api = {
register(payload: { email: string; password: string; display_name: string }) {
return request<AuthState>("/auth/register", { method: "POST", body: JSON.stringify(payload) });
async register(payload: { email: string; password: string; display_name: string }): Promise<AuthState> {
const raw = await request<{ access_token: string; user: User }>("/auth/register", { method: "POST", body: JSON.stringify(payload) });
return { accessToken: raw.access_token, user: raw.user };
},
login(payload: { email: string; password: string }) {
return request<AuthState>("/auth/login", { method: "POST", body: JSON.stringify(payload) });
async login(payload: { email: string; password: string }): Promise<AuthState> {
const raw = await request<{ access_token: string; user: User }>("/auth/login", { method: "POST", body: JSON.stringify(payload) });
return { accessToken: raw.access_token, user: raw.user };
},
me(token: string) {
return request<User>("/me", {}, token);