next-api-decorators
next-api-decorators copied to clipboard
How to create params decorator with async function
I created fullstack next js using next-auth and next-api-decorator. I want to get my user information in params
async function getSessionToken(req: NextApiRequest): Promise<JWT | null> {
const token = await getToken({req});
return token;
}
export const Session = createParamDecorator<JWT | undefined>(async (req) => {
const sessionToken = await getSessionToken(req);
return sessionToken || undefined;
});
src/apiDecorators/decorator/session.ts|12 col 62-78 error| Argument of type '(req: NextApiRequest) => Promise<JWT | undefined>' is not assignable to parameter of type 'ParamDecorator<JWT | undefined>'. Type 'Promise<JWT | undefined>' is not assignable to type 'JWT'. Index signature for type 'string' is missing in type 'Promise<JWT | undefined>'.
source : https://next-auth.js.org/configuration/nextjs#in-api-routes