Deleting the access token stored in the cookie prior to making an axios request

I've been facing a challenge in a Vue project where the request headers have become too large for our servers to handle, resulting in 413 error codes.

Using JWT bearer tokens, I can see that the token is included in the request as the Authentication header and also in the cookie under access_token.

So far, I have attempted to resolve this issue by utilizing https://www.npmjs.com/package/vue-cookies, removing the access_token cookie before each request, setting access_token=null before each request, but to no avail.

I have also experimented with axios interceptors in the hopes of removing the cookie before each request, but have encountered difficulties modifying or removing the cookie via the interceptor.

Is there a way to modify the cookie before requests, am I approaching the problem incorrectly, or would it be better to increase the allowed HTTP header size limit?

An example of the HTTP headers for a request is provided below:


Host: *URL_HERE*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
X-Requested-With: XMLHttpRequest
Cache-Control: no-cache
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...(truncated)
Connection: keep-alive
Referer: *URL_HERE*
Cookie: $netminers_$nmuid=921651885; $netminers_$(truncated)
Pragma: no-cache

Here are my getters:

public get(restUrl: string, api?: API): AxiosPromise<any> {
    return axios.get(this.withApi(restUrl, api), this.requestConf());
  }

The requestconf method:

private requestConf(): AxiosRequestConfig {
    const token = authService.getJwt();
    const headers: any = {
      'X-Requested-With': 'XMLHttpRequest',
      'Cache-Control': 'no-cache'
    };
    if (!token) {
      console.warn('User is not logged in!');
    } else {
      headers.Authorization = `Bearer ${token}`;
    }
    return {
      headers
    };
  }

Answer №1

Maybe consider utilizing the config object for setting headers. Additionally, you have the option to set headers per application using the create instance configuration. Check out more information here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with vue.js not recognizing the 'require' function

I am a newcomer to Vue and I am trying to create a basic SPA using Vue without vue-router. Following the example of vue-2.0-simple-routing-example, I am attempting to load pages using require(dynamicPathToFile+'.vue'). However, this approach is n ...

Is it possible to trigger the @click event in Vuejs when utilizing v-html to render HTML content?

Here is an interesting HTML scenario: errorText: '<a class="button" @click.prevent="enableExceedable(issue.mapping)">Enable exceedable limits</a>'; I am trying to insert this string into the following div: <div v-if="hasIssue != ...

Step-by-Step Guide on Incorporating leaflet-control-geocoder into Angular 12.x

After successfully integrating Leaflet into Angular 12 using the following commands: npm install leaflet npm install @asymmetrik/ngx-leaflet npm install --save-dev @types/leaflet I made sure to include the styles: ./node_modules/leaflet/dist/leaflet.css i ...

Oops! There seems to be an issue with the table component in the project. The error is coming from the babel-loader and vue-loader while trying to load the script for the table.vue file. Let

Encountering an issue when loading Vue components from the same folder in Vue.js. The import seems to be done correctly, but during the build process, the following error is displayed. ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/l ...

Guide on running PHP (WAMP Server) and Angular 2 (Typescript with Node.js) concurrently on a local PC

My goal is to create a Web app utilizing PHP as the server-side language and Angular 2 as the MVC framework. While researching Angular 2, I discovered that it is best practice to install Node.js and npm first since Angular 2 utilizes Typescript. Despite ha ...

Transferring information using TypeScript

My issue arises when transferring data from HTML in the following format Karbohidrat :{{karbohidrat}} <button ion-button (click)="cekHalamanMakanan('karbohidrat')">View carbohydrate foods</button> <br> Then, I retrieve the kar ...

Matching the appropriate data type for interface attributes

In the process of developing a module (module1), I have defined the following interface type: interface ModuleOneInterface { keyOne: customInterface; keyTwo: customInterface; keyThree: customInterface; } Now, as I work on another module (modul ...

Is there a way for React to recognize index.ts as the root file of a folder?

I recently started working on a new React project and I'm facing an issue with resolving the index.js file as the folder being imported in another component. Expected outcome: No errors // src/pages/router.tsx import HomePage from './home-page` ...

Mastering the art of constraining TypeScript function parameters using interface properties

Hey there, I've been exploring ways to restrict a function parameter so that it only accepts "strings" related to interface properties, similar to what I achieved in the validate fields function: Please note: The TypeScript code provided here is simp ...

The Object filter is experiencing a delay with processing 10,000 items

When an API returns over 10,000 objects in the format of {firstName:'john',lastName:'Cena'}, I am faced with a performance issue. In my parent React component, I make the API call in componentDidMount and pass this object to child compo ...

Implementing pagination and filtering in a single MERN controller

Is it possible to implement pagination and filtering in the same controller? Filter service:- const filterPosts = async (filterData, token) => { const config = { headers: { Authorization: `Bearer ${token}`, }, data: { ...

What is the process for accessing my PayPal Sandbox account?

I'm having trouble logging into my SandBox Account since they updated the menu. The old steps mentioned in this post Can't login to paypal sandbox no longer seem to work. Could someone please provide me with detailed, step-by-step instructions o ...

Jest: A guide to successfully mocking vue-router in vuex

When using vue-router inside actions of vuex, everything works smoothly on localhost. However, I encountered errors when trying to set up the store (for mocking) by importing "actions" from the store file. Can someone assist me with this issue? Versions ...

Is it possible to utilize the output of a function to determine the styling of a div element in Vue?

Hi, I'm trying to use the v-bind:style in my div to apply the textposit function with the textpos prop as a parameter. The function should adjust the style of the div based on the value of the parameter. <div class="container" :style=&qu ...

Implement Vue.js transitions on elements to smoothly reveal additional content

Rather than a problem, this is more of a "how to" scenario. Imagine having a template structured like this (id tags are used for clarity) : <template> <div id="1" v-if="someCondition"></div> <div id="2" ...

Converting Typescript Object Types to Array Types with Tuple Structures

Presently, I have the following: interface Obj { foo: string, bar: number, baz: boolean } The desired outcome is to convert this interface into the tuple format below: [string, number, boolean] Is there a way to achieve this conversion? Up ...

Exploring a JSON Object in TypeScript: A Step-by-Step Guide

I am currently utilizing Angular 7 and have a query that returns JSON data with a specific format: [ { "text": "test 1", "value": "1", "nbr": "1", "children": [ { "text": "test 1_1", ...

Angular 4 with Typescript allows for the quick and easy deletion of multiple selected rows

I am currently working on an application where I need to create a function that will delete the selected checkboxes from an array. I have managed to log the number of checkboxes that are selected, but I am struggling to retrieve the index numbers of these ...

What is the best way to display a "No Data" message on a Pie Chart in VueJS when there is no data available?

Initially, I just want to display 'No Data' when the user selects something without any data showing up. I tried using v-if in VueJS and even added some JavaScript code, but unfortunately, it did not work as expected. Can anyone assist me with th ...

What kind of type is recommended to use when working with async dispatch in coding?

For my TypeScript and React project, I am currently working on an action file called loginAction.tsx. In this file, there is a specific line of code that handles the login functionality: export const login = (obj) => async dispatch => { dispatch( ...