fix: first login error (close #385)

This commit is contained in:
1808837298@qq.com 2024-07-23 18:25:43 +08:00
parent 3875b141c6
commit caaecb8d54
2 changed files with 14 additions and 2 deletions

View File

@ -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({

View File

@ -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) => {