feat: 更新了部分依赖包的开发状态标记

This commit is contained in:
zyh
2024-10-22 02:46:31 +00:00
parent 663bc4c3b0
commit cd5b6243a5
14 changed files with 366 additions and 46 deletions

View File

@@ -0,0 +1,48 @@
import React, { useState } from 'react';
import { useNavigate } from '@remix-run/react';
export function Login() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const navigate = useNavigate();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
const response = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
if (response.ok) {
const data = (await response.json()) as { token: string };
localStorage.setItem('token', data.token);
navigate('/dashboard');
} else {
// 处理错误
}
} catch (error) {
console.error('Login failed:', error);
}
};
return (
<form onSubmit={handleSubmit}>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="邮箱"
required
/>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="密码"
required
/>
<button type="submit"></button>
</form>
);
}

View File

@@ -0,0 +1,54 @@
import React, { useState } from 'react';
import { useNavigate } from '@remix-run/react';
export function Register() {
const [username, setUsername] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const navigate = useNavigate();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
const response = await fetch('/api/auth/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, email, password }),
});
if (response.ok) {
navigate('/login');
} else {
// 处理错误
}
} catch (error) {
console.error('Registration failed:', error);
}
};
return (
<form onSubmit={handleSubmit}>
<input
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="用户名"
required
/>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="邮箱"
required
/>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="密码"
required
/>
<button type="submit"></button>
</form>
);
}