Integrate Magic passwordless authentication with your Passport.js application.
License · Changelog · Contributing Guide
See the developer documentation to learn how you can integrate Magic into your Passport.js application in a matter of minutes.
Integrating your Passport.js application with Magic will require our server-side NPM package:
# Via NPM:
npm install --save passport-magic
# Via Yarn:
yarn add passport-magic
const passport = require("passport");
const MagicStrategy = require("passport-magic").Strategy;
const strategy = new MagicStrategy(async function(user, done) {
const userMetadata = await magic.users.getMetadataByIssuer(user.issuer);
const existingUser = await users.findOne({ issuer: user.issuer });
if (!existingUser) {
/* Create new user if doesn't exist */
return signup(user, userMetadata, done);
} else {
/* Login user if otherwise */
return login(user, done);
}
});
passport.use(strategy);