34 lines
930 B
TypeScript
34 lines
930 B
TypeScript
import defaultHeaders from '../../configuration/defaultHeaders';
|
|
import getApiUrl from '../../configuration/getApiUrl';
|
|
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
import getCookie from '../../functions/getCookie';
|
|
|
|
export type ValidatedCookieType = {
|
|
cookie_enabled: boolean;
|
|
status: boolean;
|
|
validated: number;
|
|
validated_str: string;
|
|
cookie_validated?: boolean;
|
|
};
|
|
|
|
const updateCookie = async (): Promise<ValidatedCookieType> => {
|
|
const apiUrl = getApiUrl();
|
|
const csrfCookie = getCookie('csrftoken');
|
|
|
|
const response = await fetch(`${apiUrl}/api/appsettings/cookie/`, {
|
|
method: 'POST',
|
|
headers: {
|
|
...defaultHeaders,
|
|
'X-CSRFToken': csrfCookie || '',
|
|
},
|
|
credentials: getFetchCredentials(),
|
|
});
|
|
|
|
const validatedCookie = await response.json();
|
|
console.log('updateCookie', validatedCookie);
|
|
|
|
return validatedCookie;
|
|
};
|
|
|
|
export default updateCookie;
|