refactor: 移除 Token 配置
This commit is contained in:
@@ -9,16 +9,11 @@ const webClient = axios.create({
|
|||||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||||
timeout: dayjs.duration({ seconds: 10 }).asMilliseconds(),
|
timeout: dayjs.duration({ seconds: 10 }).asMilliseconds(),
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
withXSRFToken: true
|
withXSRFToken: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
webClient.interceptors.request.use(
|
webClient.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
const state = store.getState()
|
|
||||||
if (state.auth.isAuthenticated) {
|
|
||||||
config.headers["Authorization"] = `Bearer ${state.auth.token!}`
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
(error: unknown) => {
|
(error: unknown) => {
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ import type { User } from "@/types/entity"
|
|||||||
interface AuthState {
|
interface AuthState {
|
||||||
isAuthenticated: boolean
|
isAuthenticated: boolean
|
||||||
user: User | null
|
user: User | null
|
||||||
token: string | null,
|
|
||||||
registrationEnabled: boolean
|
registrationEnabled: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: AuthState = {
|
const initialState: AuthState = {
|
||||||
isAuthenticated: false,
|
isAuthenticated: false,
|
||||||
user: null,
|
user: null,
|
||||||
token: null,
|
|
||||||
registrationEnabled: false
|
registrationEnabled: false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,18 +21,15 @@ const authSlice = createSlice({
|
|||||||
state,
|
state,
|
||||||
action: PayloadAction<{
|
action: PayloadAction<{
|
||||||
user: User
|
user: User
|
||||||
token: string
|
|
||||||
}>
|
}>
|
||||||
) {
|
) {
|
||||||
console.log("更新用户信息:", action.payload.user)
|
console.log("更新用户信息:", action.payload.user)
|
||||||
state.isAuthenticated = true
|
state.isAuthenticated = true
|
||||||
state.user = action.payload.user
|
state.user = action.payload.user
|
||||||
state.token = action.payload.token
|
|
||||||
},
|
},
|
||||||
logout(state) {
|
logout(state) {
|
||||||
state.isAuthenticated = false
|
state.isAuthenticated = false
|
||||||
state.user = null
|
state.user = null
|
||||||
state.token = null
|
|
||||||
},
|
},
|
||||||
updateRegistrationEnabled(state, action: PayloadAction<boolean>) {
|
updateRegistrationEnabled(state, action: PayloadAction<boolean>) {
|
||||||
state.registrationEnabled = action.payload
|
state.registrationEnabled = action.payload
|
||||||
|
|||||||
Reference in New Issue
Block a user