@telegram-auth/server
Zero dependency package to validate the data received from Telegram Login Widget or Web App, compatible with Node, serverless edge networks and web workers.
@telegram-auth/server exports a TS/JS class (AuthDataValidator) to validate the data received from Telegram Login Widget and Telegram Web Apps.
It also exports some utility functions to prepare the data for validation.
Documentation
Install
npm install @telegram-auth/server
yarn add @telegram-auth/server
pnpm add @telegram-auth/server
Usage
import { AuthDataValidator } from '@telegram-auth/server';
import { urlStrToAuthDataMap } from '@telegram-auth/server/utils';
const validator = new AuthDataValidator({ botToken: process.env.BOT_TOKEN });
const data = urlStrToAuthDataMap(request.url);
try {
const user = await validator.validate(data);
console.log(user);
} catch (error) {
console.error(error);
}