node-telegram-login
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

node-telegram-login

Build Status npm version devDependency Status GitHub issues GitHub stars GitHub license

Check Telegram Login Widget hash manually or with an express.js middleware

Installation

Install through npm:

npm install --save node-telegram-login

Usage

Use it in your app like so:

const TOKEN = '<BOT_TOKEN>'
const TelegramLogin = require('node-telegram-login');
const MySiteLogin = new TelegramLogin(TOKEN);
 
if(MySiteLogin.checkLoginData(data)) console.log('Data is from telegram! ;)');
if(!MySiteLogin.checkLoginData(data)) console.log('Data is NOT from telegram :(')

You can use it like an express.js middleware like this:

const TOKEN = '<BOT_TOKEN>'
const TelegramLogin = require('node-telegram-login');
const MySiteLogin = new TelegramLogin(TOKEN);
 
app.get('/login', MySiteLogin.defaultMiddleware(), (req, res) => {
  console.log(res.locals.telegram_user) //null if not from telegram, contains login data otherwise;
});
 

Also it is possible to set a custom middleware with specified success and fail functions. Success function will be called with req, res, next and the login_data. Fail function will be called with req, res, next arguments. In this case you are responsable of calling next()

const TOKEN = '<BOT_TOKEN>'
const TelegramLogin = require('node-telegram-login');
const MySiteLogin = new TelegramLogin(TOKEN);
 
let success = (req,res,next,login_data) => {
  res.locals.telegram_user = login_data;
  next();
}
 
let fail = (req,res,next) => {
  res.sendStatus(403);
}
 
app.get('/login', MySiteLogin.customMiddleware(success, fail), (req, res) => {
  //do your stuff;
});
 

Package Sidebar

Install

npm i node-telegram-login

Weekly Downloads

146

Version

2.0.0

License

MIT

Unpacked Size

16.2 kB

Total Files

15

Last publish

Collaborators

  • marcelloghiozzi