feat(安全): 实现JWT认证和HTTPS支持

- 添加JWT认证中间件保护API端点
- 在登录流程中使用bcrypt哈希密码和JWT令牌
- 配置HTTPS服务器使用自签名证书
- 更新前端API调用以包含认证令牌
This commit is contained in:
sudomarcma
2025-06-26 10:41:23 +08:00
parent 0ed8e4af30
commit e563f17283
10 changed files with 1357 additions and 69 deletions
+6
View File
@@ -1,12 +1,18 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
export async function apiFetch(endpoint, options = {}) {
const token = sessionStorage.getItem('token')
const defaultHeaders = {
'ngrok-skip-browser-warning': 'true',
'Content-Type': 'application/json',
...options.headers,
}
if (token) {
defaultHeaders['Authorization'] = `Bearer ${token}`
}
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
...options,
headers: defaultHeaders,