feat: 实现登录功能,包括用户名和密码输入、表单验证及错误处理

This commit is contained in:
2025-12-24 23:09:14 +08:00
parent 21cbb60480
commit 2a3e951acb
3 changed files with 117 additions and 14 deletions

View File

@@ -1,6 +1,16 @@
import { requestJson } from './apiClient';
import { setTokenAndLoadMe } from './session';
export async function login({ username, password }) {
const data = await requestJson('/v1/auth/login', {
method: 'POST',
body: { username, password }
});
const token = data?.token ?? '';
if (token) await setTokenAndLoadMe(token);
return token;
}
export async function register({ username, password, confirmPassword, verifyCode }) {
const data = await requestJson('/v1/auth/register', {
method: 'POST',