How can I retrieve the session data from endpoint when data is sent from stripe's server?
Unanswered
Chinese Alligator posted this in #help-forum
Chinese AlligatorOP
I'm using next-iron-session for session storage and I need to use Cors at same time, in my endpoint. I export the model's default handler function like this:
So I retrieve data from the session like this:
But when the POST data cames from stripe server the session isn't available. How can I get the session? it isn't available even from a fetch call ta a page that return the session:
returns
the
How can I fix that and get the session data from the endpoint when the post data is sent from stripe server?
const withSessionRoute = (handler: (req: NextApiRequest, res: NextApiResponse) => Promise<void>) => {
return withIronSessionApiRoute(cors(handler), ironOptions);
}
export default withSessionRoute(handler);So I retrieve data from the session like this:
const handler = async (
req: NextApiRequest,
res: NextApiResponse
) => {
console.log('req.session = ', req.session);
// ...
}But when the POST data cames from stripe server the session isn't available. How can I get the session? it isn't available even from a fetch call ta a page that return the session:
const response = await fetch('http://localhost:3000/api/baa');
const result = await response.json();
console.log('result = ', result);returns
{id: -1}the
baa page goes like this:import { NextApiRequest, NextApiResponse } from 'next';
import { withIronSessionApiRoute, withIronSessionSsr } from "iron-session/next";
import CustomSession from '@/interfaces/CustomSession';
import IUser from '@/interfaces/IUser';
import { withSessionRoute } from "@lib/withSession";
const handler = async (
req: NextApiRequest,
res: NextApiResponse
) => {
const user:IUser = (req.session as CustomSession)?.user || {id: -1};
res.status(200).json(user);
}
export default withSessionRoute(handler);withSessionRoute goes like this:const withSessionRoute = (handler: NextApiHandler) => {
return withIronSessionApiRoute(handler, ironOptions);
}How can I fix that and get the session data from the endpoint when the post data is sent from stripe server?