Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create params decorator with async function #628

Open
reynoldputra opened this issue Jul 13, 2023 · 0 comments
Open

How to create params decorator with async function #628

reynoldputra opened this issue Jul 13, 2023 · 0 comments

Comments

@reynoldputra
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant