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

sendLink href has added undefined #29

Open
Uncle798 opened this issue Feb 10, 2023 · 0 comments
Open

sendLink href has added undefined #29

Uncle798 opened this issue Feb 10, 2023 · 0 comments

Comments

@Uncle798
Copy link

Uncle798 commented Feb 10, 2023

The href being generated by the sendMagicLink function seems be adding 'undefined' before the question mark and token=.
Here is my strategy:

const magicLogin = new MagicLoginStrategy({
  secret: process.env.MAGIC_LINK_SECRET,
  callbackURL: '/auth/magiclogin/callback',
  sendMagicLink: async (destination, href) => {
    try {
      console.log(href)
      await sendEmail(destination.email, destination.givenName, href);
    } catch (error) {
      console.error(error);
    }
  },
  verify: async (payload, callback) => {
    try {
      const dbUser = await prisma.user.upsert({
        where: {
          email: payload.destination,
        },
        update: {
          updatedAt: new Date(Date.now()),
        },
        create: {
          data: {
            email: payload.destination,
            emailVerified: new Date(Date.now()),
          },
        },
        include: {
          employee: {
            select: {
              userId: true,
              isAdmin: true,
            },
          },
        },
      });
      return callback(null, dbUser);
    } catch (error) {
      return callback(error);
    }
  },
});
passport.use(magicLogin);

router.post('/sendlink', magicLogin.send);
router.get('/magiclogin/callback', passport.authenticate('magiclogin'));

The href that is passed to my sendMail function looks like this:

undefined?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXN0aW5hdGlvbiI6eyJlbWFpbCI6ImVyaWMuYnJhbnNvbkBnbWFpbC5jb20iLCJnaXZlbk5hbWUiOiJFcmljIn0sImNvZGUiOiI5OTE4MSIsImlhdCI6MTY3NjA0MzMwOCwiZXhwIjoxNjc2MDQ2OTA4fQ.9vAUmm1pAPIX-tJq8qE3HK-mRY-ZMH7qeJByIqO2RWo

I can remove the undefined but I don't know how it got there in the first place.

This is all in windows 10 in Node 18.12.1

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