1.0.0 • Published 7 years ago
email-auth v1.0.0
email-auth
Email verification for login
Installation
npm install email-auth --save
Usage
const emailAuth = require('email-auth');
// this should be a database really
let nextID = 0;
const tokens = {};
const client = createClient({
saveToken({email, token, expiry}) {
// save the token and return the id of the saved token, this can return a Promise
const id = nextID++;
tokens[id] = {email, token, expiry};
return id;
},
getTokenByID(id) {
// get the token at that id, can return a Promise
return tokens[id];
},
sendEmail({toAddress, url}) {
// send the message using to the to email asking the user to click on the url
},
});
// to send verification e-mail
client.sendMessage('forbes@lindesay.co.uk', 'https://example.com').done();
// to verify/complete a login
app.get('/', (req, res, next) => {
if (req.query.token_id && req.query.token) {
client.verifyToken(req.query.token_id, req.query.token).done(email => {
// log the user in
}, next);
}
// show the user a login page
})
License
MIT