Essentially what I am trying to do is pass the auth0 user ID to an API route in my application which calls a stripe endpoint which then creates a customer portal session. I need to pass the user ID to the api call but I am unable to call the useUser in an API route so I am unsure of how to proceed here.
const stripe = require('stripe')('some-api-key');
export default function create_customer_portal_session(req, res) {
const customerId = 'this should be the auth0 user id';
const returnUrl = 'some-return-url';
const portalSession = async () => await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: returnUrl,
});
res.redirect(303, portalSession.url);
};
Considering this is post login, perhaps you could inspect the access token (or id token) of the user and use the sub claim (Auth0 user_id) in the code above - For reference, here’s an example access token.
I ended up figuring it out. All I had to do was create a form in one of my react components and pass the auth0 user id to it and since it was on the front end it had access to the useUser hook