How to save user parameters when http basic auth?

  • 0
    I log in to the remote api, configured with basic auth. Authorization method:
    auth() {
    const token = Buffer.from(`${email}:${psw}`, 'utf8').toString('base64')
          var config = {
            method: "get",
            url:
              "http://....",
            headers: {
              Authorization: `Basic ${token}`,
            },
          };
          axios(config)
            .then(function (response) {
              console.log(JSON.stringify(response.data));
            })
            .catch(function (error) {
              console.log(error);
            });
        },


    When authorizing through a browser through a standard form, the credentials are saved and in the future you can access the server without authorization for a while.
    When sending a request, authorization is also successful, but to access the same route or another, you need to send the authorization header again or an error occurs: Failed to load resource: the server responded with a status of 401 (Unauthorized).
    Where can the title be saved? Or how to organize the work correctly?
    JavaScript Declan Best, Nov 18, 2019

  • 1 Answers
  • 0
    but to access the same route or another, you need to transmit the authorization header again


    Yes need. do this.



    You can make your own function to call the api, which will substitute the desired header into the request every time.

    And already everywhere in the application to use it.
    Delilah Collier

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!