Remove the access token from Redux & context (#30275)
This commit is contained in:
parent
2c75cf8599
commit
2c5ab8f647
35 changed files with 225 additions and 226 deletions
|
@ -2,8 +2,8 @@ import type { AxiosResponse, RawAxiosRequestHeaders } from 'axios';
|
|||
import axios from 'axios';
|
||||
import LinkHeader from 'http-link-header';
|
||||
|
||||
import { getAccessToken } from './initial_state';
|
||||
import ready from './ready';
|
||||
import type { GetState } from './store';
|
||||
|
||||
export const getLinks = (response: AxiosResponse) => {
|
||||
const value = response.headers.link as string | undefined;
|
||||
|
@ -29,30 +29,22 @@ const setCSRFHeader = () => {
|
|||
|
||||
void ready(setCSRFHeader);
|
||||
|
||||
export const authorizationTokenFromState = (getState?: GetState) => {
|
||||
return (
|
||||
getState && (getState().meta.get('access_token', '') as string | false)
|
||||
);
|
||||
};
|
||||
const authorizationTokenFromInitialState = (): RawAxiosRequestHeaders => {
|
||||
const accessToken = getAccessToken();
|
||||
|
||||
const authorizationHeaderFromState = (getState?: GetState) => {
|
||||
const accessToken = authorizationTokenFromState(getState);
|
||||
|
||||
if (!accessToken) {
|
||||
return {};
|
||||
}
|
||||
if (!accessToken) return {};
|
||||
|
||||
return {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
} as RawAxiosRequestHeaders;
|
||||
};
|
||||
};
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default function api(getState: GetState) {
|
||||
export default function api() {
|
||||
return axios.create({
|
||||
headers: {
|
||||
...csrfHeader,
|
||||
...authorizationHeaderFromState(getState),
|
||||
...authorizationTokenFromInitialState(),
|
||||
},
|
||||
|
||||
transformResponse: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue