Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not setting header #69

Open
MichaelLiss opened this issue Dec 14, 2023 · 4 comments
Open

not setting header #69

MichaelLiss opened this issue Dec 14, 2023 · 4 comments

Comments

@MichaelLiss
Copy link

MichaelLiss commented Dec 14, 2023

Added all code per the read me into a REACT (non-type script project)

Here is my code:

import { applyAuthTokenInterceptor } from 'axios-jwt';
import axios from 'axios';

const BASE_URL = 'http://localhost:5000/api/';

const axiosInstance = axios.create({ baseURL: BASE_URL });

const requestRefresh = (refresh) => {
  // Notice that this is the global axios instance, not the axiosInstance!  <-- important
  return axios.post(`${BASE_URL}/auth/refreshtoken`, { refresh }).then((response) => response.data.token);
};

applyAuthTokenInterceptor(axiosInstance, { requestRefresh }); // Notice that this uses the axiosInstance instance.  <-- important

export default axiosInstance;

Dependencies:

  "dependencies": {
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^1.6.2",
    "axios-jwt": "^3.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.20.1",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
@MichaelLiss
Copy link
Author

MichaelLiss commented Dec 14, 2023

doesn't work with 3.0.0

@MichaelLiss MichaelLiss reopened this Dec 14, 2023
@MichaelLiss MichaelLiss changed the title TypeError when running (0 , ms_1.default) is not a function Dec 14, 2023
@MichaelLiss
Copy link
Author

MichaelLiss commented Dec 14, 2023

image

event tried putting both tokens in storage:

  tokens = {
    accessToken: token1,
    refreshToken: token2,
  }
  localStorage.setItem("tokens", tokens);

image

@MichaelLiss
Copy link
Author

Authorization header is not being set:

image

@MichaelLiss
Copy link
Author

When I hard code the authorization into the header ... it works:

import axios from '../axiosApi/axiosApi';  // where the code is implemented to use this module
...

      let token = 'eyJhbGciOi <snip_for_brevity>'
      const response = await axios.get(url, { headers: {"Authorization" : `Bearer ${token}`} });

@MichaelLiss MichaelLiss changed the title (0 , ms_1.default) is not a function not setting header Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant