I’m using @auth0/nextjs-auth0 with Next.js to access an an external GraphQL api. I’m using a proxy to add the JWT to the requests that go to the GraphQL server.
The GraphQL sever is using Apollo and Node.
I’m running into an issue where the front end seems to be working fine but when it makes a request to the backend I get an error which says: “Error: jwt verify error: jwt expired”
How to a get @auth0/nextjs-auth0 to refresh the token before it’s sent?
Here’s my proxy code:
import { NextApiRequest, NextApiResponse } from "next"
import httpProxyMiddleware from "next-http-proxy-middleware"
// import { requestAccessToken } from "@/lib/apolloClient"
import { withApiAuthRequired, getSession } from '@auth0/nextjs-auth0';
export default withApiAuthRequired(async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getSession(req, res)
return (httpProxyMiddleware(req, res, {
// You can use the `http-proxy` option
target: `${NEXT_GRAPHQL_ENDPOINT}/graphql`,
// In addition, you can use the `pathRewrite` option provided by `next-http-proxy-middleware`
pathRewrite: [{
patternStr: '^/graphql',
replaceStr: '/v1/graphql'
}, {
patternStr: '^/api',
replaceStr: ''
}],
headers: {
authorization: `Bearer ${session?.idToken}`
}
})
)});