0
0
Fork 0

Remove the access token from Redux & context (#30275)

This commit is contained in:
Renaud Chaput 2024-05-22 16:45:18 +02:00 committed by GitHub
parent 2c75cf8599
commit 2c5ab8f647
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 225 additions and 226 deletions

View file

@ -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: [