#Axios Interceptor response 401 in getServerSideProps

9 messages · Page 1 of 1 (latest)

turbid shell
#

I'm having issue with getServerSideProps with axios interceptor. Its return response 401 which is unauthorised request. But when in client side in useEffect, it can be fetch the response from the server which is authorized.

so basically my axios interceptor is something like this
api.interceptors.request.use(async (request) => {
if (!request.headers.Authorization) { request.headers.Authorization =Bearer ${token}; } }

then i use
api.get(API_ROUTE).then(({data}) => data)

inside page functional component
import { getCreateCourseSchema } from 'api/API';

export const Component = () => { ... }

export async function getServerSideProps(context) {
const createSchema = await getCreateCourseSchema();

return {
    props: {
      createSchema,
    },
};

}

Why the SSR does not able to define or identify my axios interceptor even though I have set it?

molten leaf
#

where is token coming from?

turbid shell
molten leaf
#

have you tried logging the value of the token being set in the interceptor?

#

just to check if the value is being assigned correctly

turbid shell
#

i have tried check log and it does have the token. The getServerSideProps still responding 401

#

this is the header requested in ssr

molten leaf
#

it looks like the token is missing in this request, but the header is there