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> <label>
Email 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>
<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> </label>
{error && <p className="error">{error}</p>} {error && <p className="error">{error}</p>}
<button className="primary" disabled={mutation.isPending}> <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 = { export const api = {
register(payload: { email: string; password: string; display_name: string }) { async register(payload: { email: string; password: string; display_name: string }): Promise<AuthState> {
return request<AuthState>("/auth/register", { method: "POST", body: JSON.stringify(payload) }); 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 }) { async login(payload: { email: string; password: string }): Promise<AuthState> {
return request<AuthState>("/auth/login", { method: "POST", body: JSON.stringify(payload) }); 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) { me(token: string) {
return request<User>("/me", {}, token); return request<User>("/me", {}, token);
+4 -1
View File
@@ -180,11 +180,14 @@ async def progression(
kind: Annotated[str, Query(pattern="^(exercise|equipment)$")] = "exercise", kind: Annotated[str, Query(pattern="^(exercise|equipment)$")] = "exercise",
entity_id: str | None = None, entity_id: str | None = None,
) -> Any: ) -> Any:
p: dict[str, Any] = {"kind": kind}
if entity_id is not None:
p["entity_id"] = entity_id
return await logic_request( return await logic_request(
"GET", "GET",
"/internal/analytics/progression", "/internal/analytics/progression",
user, user,
params={"kind": kind, "entity_id": entity_id}, params=p,
) )
+2 -2
View File
@@ -351,8 +351,8 @@ def recalculate_workout_calories(db: Session, workout_id: uuid.UUID) -> None:
def get_progression( def get_progression(
db: Db, db: Db,
user_id: CurrentUserId, user_id: CurrentUserId,
kind: str = Query(pattern="^(exercise|equipment)$"), kind: Annotated[str, Query(pattern="^(exercise|equipment)$")],
entity_id: uuid.UUID | None = None, entity_id: Annotated[uuid.UUID | None, Query()] = None,
) -> ProgressionRead: ) -> ProgressionRead:
statement = ( statement = (
select(Workout.started_at, WorkoutSet.weight, WorkoutSet.reps) select(Workout.started_at, WorkoutSet.weight, WorkoutSet.reps)