I have a Next.js application deployed on Vercel, and I’m facing issues with calling internal APIs that are protected with authentication(auth.js). In development and a custom build, I successfully used the token from the cookie and passed it as a cookie in the header. However, this method doesn’t work in production on Vercel.
/api/get-token - Protected Route with middleware/auth.js
export async function GET(){
// retuning token from here.
}
/api/get-order-details - Protected Route with middleware/auth.js
export async function GET(){
const res = await axios.get(`${DOMAIN}api/get-token`);
const token = res.data.token;
// other
}
What is the correct way to call internal APIs protected with authentication in a Next.js application deployed on Vercel?