NextAuth With NextJS FE & Express BE
Unanswered
American black bear posted this in #help-forum
American black bearOP
i need my backend API to not be on nextjs for some reason.
i am using express + TRPC on it
trying to integrate nextauth on the backend, by extracting session from req and calling
however, the
How can i cast these normal req & res to the nextapi ones? is it just type thing or do i actually need to add logic here?
i am using express + TRPC on it
trying to integrate nextauth on the backend, by extracting session from req and calling
auth() provided by nextauth on v5, in order to validate the user and add it to my middleware contexthowever, the
auth() function expects req, res params of type NextApiRequest and NextApiResponse, whilst my req & res are normal ones provided by express.How can i cast these normal req & res to the nextapi ones? is it just type thing or do i actually need to add logic here?
export async function createContextInner(opts: trpcExpress.CreateExpressContextOptions) {
const req = opts.req;
const res = opts.res;
const session = req && res && (await
/*
* Argument of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'NextApiRequest'.
Property 'env' is missing in type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' but required in type 'NextApiRequest'.ts(234
*/
auth(req, res));
return { session };
}