Closed siang13 closed 2 months ago
You can use Axios interceptors to inject the access token, ie:
axios.interceptors.request.use(
(config) => {
const oidcStorage = localStorage.getItem('oidc.default');
const { tokens } = JSON.parse(oidcStorage || '{}');
/* eslint-disable no-param-reassign */
config.baseURL = process.env.NEXT_PUBLIC_API_BASE;
if (config.headers) {
config.headers.Authorization = `Bearer ${tokens.accessToken}`;
}
return config;
},
(error) => Promise.reject(error)
);
You can use Axios interceptors to inject the access token, ie:
axios.interceptors.request.use( (config) => { const oidcStorage = localStorage.getItem('oidc.default'); const { tokens } = JSON.parse(oidcStorage || '{}'); /* eslint-disable no-param-reassign */ config.baseURL = process.env.NEXT_PUBLIC_API_BASE; if (config.headers) { config.headers.Authorization = `Bearer ${tokens.accessToken}`; } return config; }, (error) => Promise.reject(error) );
Is this working with service workers as well? Because the token can only be accessed by the service worker.
Service worker will work with Axios or fetch without useOidcFetch hooks. Thank you.
Issue and Steps to Reproduce
Can check is it possible to use Axios and service workers for fetching