Second revision
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
// Base URL for your Flask API - IMPORTANT: Adjust if your backend runs elsewhere
|
||||
// 后端 Flask API 的基础 URL - 重要:如果后端运行在别处,请调整
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5000'; // Assuming Flask runs on port 5000
|
||||
const API_BASE_URL = 'http://localhost:5000'; // Assuming Flask runs on port 5000
|
||||
|
||||
// --- Helper function to get Auth Token ---
|
||||
// --- 获取认证 Token 的辅助函数 ---
|
||||
@@ -27,7 +27,7 @@ const handleUnauthorized = () => {
|
||||
export const loginUser = async (username, password) => {
|
||||
console.log('API: Attempting login with username...');
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/login`, { // Endpoint from auth.py
|
||||
const response = await fetch(`${API_BASE_URL}/api/auth/login`, { // FIX: Changed from /api/login to /api/auth/login
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: username, password: password }),
|
||||
@@ -36,7 +36,7 @@ export const loginUser = async (username, password) => {
|
||||
if (!response.ok) throw new Error(data.message || `HTTP error! status: ${response.status}`);
|
||||
if (data.token) {
|
||||
console.log('API: Login successful, token received.');
|
||||
return data; // Contains { message, token, user_id }
|
||||
return data; // Contains { message, token, user }
|
||||
} else {
|
||||
throw new Error('Login successful but no token received from server.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user