feat: remove csrf from the client (#42242)
This commit is contained in:
committed by
GitHub
parent
017ae24894
commit
1ba9d03cb5
@@ -1,5 +1,4 @@
|
||||
import envData from '../../../config/env.json';
|
||||
import Tokens from 'csrf';
|
||||
import cookies from 'browser-cookies';
|
||||
|
||||
import type { UserType } from '../redux/prop-types';
|
||||
@@ -7,21 +6,17 @@ import type { UserType } from '../redux/prop-types';
|
||||
const { apiLocation } = envData;
|
||||
|
||||
const base = apiLocation;
|
||||
const tokens = new Tokens();
|
||||
|
||||
const defaultOptions: RequestInit = {
|
||||
credentials: 'include'
|
||||
};
|
||||
|
||||
// _csrf is passed to the client as a cookie. Tokens are sent back to the server
|
||||
// via headers:
|
||||
// csrf_token is passed to the client as a cookie. The client must send
|
||||
// this back as a header.
|
||||
function getCSRFToken() {
|
||||
const _csrf = typeof window !== 'undefined' && cookies.get('_csrf');
|
||||
if (!_csrf) {
|
||||
return '';
|
||||
} else {
|
||||
return tokens.create(_csrf);
|
||||
}
|
||||
const token =
|
||||
typeof window !== 'undefined' ? cookies.get('csrf_token') : null;
|
||||
return token ?? '';
|
||||
}
|
||||
|
||||
async function get<T>(path: string): Promise<T> {
|
||||
|
Reference in New Issue
Block a user