Enhance authentication input fields with autocomplete attributes and refactor API registration and login methods for improved response handling
This commit is contained in:
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user