diff --git a/vue3/src/openapi/runtime.ts b/vue3/src/openapi/runtime.ts index ed079edb5..9920fa69a 100644 --- a/vue3/src/openapi/runtime.ts +++ b/vue3/src/openapi/runtime.ts @@ -1,5 +1,7 @@ /* tslint:disable */ /* eslint-disable */ +import {getCookie} from "@/utils/cookie"; + /** * Django Recipes * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) @@ -140,21 +142,6 @@ export class BaseAPI { throw new ResponseError(response, 'Response returned an error code'); } - private getCookie(name: string) { - let cookieValue = null; - if (document.cookie && document.cookie !== '') { - const cookies = document.cookie.split(';'); - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i].trim(); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; - } private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { let url = this.configuration.basePath + context.path; if (context.query !== undefined && Object.keys(context.query).length !== 0) { @@ -164,7 +151,7 @@ export class BaseAPI { url += '?' + this.configuration.queryParamsStringify(context.query); } - const headers = Object.assign({}, this.configuration.headers, context.headers, { 'X-CSRFToken': this.getCookie('csrftoken'), }); + const headers = Object.assign({}, this.configuration.headers, context.headers, { 'X-CSRFToken': getCookie('csrftoken'), }); Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); const initOverrideFn = diff --git a/vue3/src/utils/cookie.ts b/vue3/src/utils/cookie.ts new file mode 100644 index 000000000..3b1d23188 --- /dev/null +++ b/vue3/src/utils/cookie.ts @@ -0,0 +1,19 @@ +/** + * simple function to retrieve a cookie by name + * @param name name of the cookie + */ +export function getCookie(name: string) { + let cookieValue = null; + if (document.cookie && document.cookie !== '') { + const cookies = document.cookie.split(';'); + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} \ No newline at end of file