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

fastify support #31

Open
rodrigo1991 opened this issue Jul 11, 2023 · 2 comments
Open

fastify support #31

rodrigo1991 opened this issue Jul 11, 2023 · 2 comments

Comments

@rodrigo1991
Copy link

Please change
res.json({ success: true, code: code });

to
res.send({ success: true, code: code });

to make it work on both express and fastify router

@hfersu
Copy link

hfersu commented Sep 12, 2023

I have encountered this error:

TypeError: res.json is not a function
    at /app_path/node_modules/passport-magic-login/src/index.ts:105:13
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: res.json is not a function
    at /app_path/node_modules/passport-magic-login/src/index.ts:109:13
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

It occurs right after sending the email with the MagicLink to the user.
I'm not sure if it could be related to this Issue since I'm also using Fastify (with NestJs).

EDIT: Using NestJs through Express, I don't get the above-mentioned error, so I understand that this is the reason for the failure.

@J-Sek
Copy link

J-Sek commented Feb 24, 2024

Example workaround for unpatient people.

@Post('login')
loginWithLink(@Req() req, @Res() res) {
  this.passwordlessStrategy.send(req, {
    ...res,
    status: (code) => {
      res.statusCode = code;
      return res;
    },
    json: res.send.bind(res),
  });
}

The underlying project is based on Nest.js, but hopefully you get the idea. Patch json() and status()

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

3 participants