diff --git a/web/src/components/LoginForm.js b/web/src/components/LoginForm.js index 0fecf10..3cd56a1 100644 --- a/web/src/components/LoginForm.js +++ b/web/src/components/LoginForm.js @@ -1,7 +1,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { Link, useNavigate, useSearchParams } from 'react-router-dom'; import { UserContext } from '../context/User'; -import { API, getLogo, showError, showInfo, showSuccess } from '../helpers'; +import { API, getLogo, showError, showInfo, showSuccess, updateAPI } from '../helpers'; import { onGitHubOAuthClicked } from './utils'; import Turnstile from 'react-turnstile'; import { @@ -101,6 +101,7 @@ const LoginForm = () => { if (success) { userDispatch({ type: 'login', payload: data }); setUserData(data); + updateAPI() showSuccess('登录成功!'); if (username === 'root' && password === '123456') { Modal.error({ diff --git a/web/src/helpers/api.js b/web/src/helpers/api.js index 51b99d1..67f3e3c 100644 --- a/web/src/helpers/api.js +++ b/web/src/helpers/api.js @@ -1,7 +1,7 @@ import { getUserIdFromLocalStorage, showError } from './utils'; import axios from 'axios'; -export const API = axios.create({ +export let API = axios.create({ baseURL: import.meta.env.VITE_REACT_APP_SERVER_URL ? import.meta.env.VITE_REACT_APP_SERVER_URL : '', @@ -10,6 +10,17 @@ export const API = axios.create({ } }); +export function updateAPI() { + API = axios.create({ + baseURL: import.meta.env.VITE_REACT_APP_SERVER_URL + ? import.meta.env.VITE_REACT_APP_SERVER_URL + : '', + headers: { + 'New-API-User': getUserIdFromLocalStorage() + } + }); +} + API.interceptors.response.use( (response) => response, (error) => {