Skip to content

How to create params decorator with async function #628

@reynoldputra

Description

@reynoldputra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions