mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-23 02:26:36 +08:00
fix: first login error (close #385)
This commit is contained in:
parent
3875b141c6
commit
caaecb8d54
@ -1,7 +1,7 @@
|
|||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { UserContext } from '../context/User';
|
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 { onGitHubOAuthClicked } from './utils';
|
||||||
import Turnstile from 'react-turnstile';
|
import Turnstile from 'react-turnstile';
|
||||||
import {
|
import {
|
||||||
@ -101,6 +101,7 @@ const LoginForm = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
userDispatch({ type: 'login', payload: data });
|
userDispatch({ type: 'login', payload: data });
|
||||||
setUserData(data);
|
setUserData(data);
|
||||||
|
updateAPI()
|
||||||
showSuccess('登录成功!');
|
showSuccess('登录成功!');
|
||||||
if (username === 'root' && password === '123456') {
|
if (username === 'root' && password === '123456') {
|
||||||
Modal.error({
|
Modal.error({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { getUserIdFromLocalStorage, showError } from './utils';
|
import { getUserIdFromLocalStorage, showError } from './utils';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export const API = axios.create({
|
export let API = axios.create({
|
||||||
baseURL: import.meta.env.VITE_REACT_APP_SERVER_URL
|
baseURL: import.meta.env.VITE_REACT_APP_SERVER_URL
|
||||||
? 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(
|
API.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user