feat: 实现登录功能,包括用户名和密码输入、表单验证及错误处理
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user