Skip to content
Discussion options

You must be logged in to vote

I figured it out, I added withCredentials to the axios instance then passed the cookie to the request on server side.

It now passes the cookie with the request from the server to API route.

// apiClient.ts
const baseConfig: AxiosRequestConfig = {
    baseURL: API_DOMAIN,
    withCredentials: true,
    headers: {
        'Content-Type': 'application/json',
    },
};

const apiClient = axios.create(baseConfig);
function getAuthSession(
    ...args:
        | [GetServerSidePropsContext['req'], GetServerSidePropsContext['res']]
        | [NextApiRequest, NextApiResponse]
        | []
) {
    return getServerSession(...args, authOptions);
}

// page.ts
export const getServerSideProps: GetServe…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jinsley8
Comment options

@jinsley8
Comment options

Answer selected by jinsley8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants