@telegram-auth/server
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@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
npm install @telegram-auth/server

# yarn
yarn add @telegram-auth/server

# with pnpm
pnpm add @telegram-auth/server

Usage

import { AuthDataValidator } from '@telegram-auth/server';
import { urlStrToAuthDataMap } from '@telegram-auth/server/utils';

// initialize the validator with your bot token
const validator = new AuthDataValidator({ botToken: process.env.BOT_TOKEN });

// convert the data from the URL to a map
const data = urlStrToAuthDataMap(request.url);

try {
    // validate the data by passing the map to the validator
    const user = await validator.validate(data);

    // The data is now valid and you can sign in the user.

    console.log(user);
} catch (error) {
    console.error(error);
}

Package Sidebar

Install

npm i @telegram-auth/server

Weekly Downloads

1,115

Version

1.0.3

License

MIT

Unpacked Size

73.6 kB

Total Files

75

Last publish

Collaborators

  • manzoorwanijk