hprobotic / react-telegram-login

A React Telegram Login Widget Component
https://core.telegram.org/widgets/login
MIT License
130 stars 29 forks source link
telegram-login telegram-react telegram-web-login

React Telegram Login

A Telegram OAuth Sign-in / Log-in Component for React

Code

Install

npm install react-telegram-login

or

yarn add react-telegram-login

How to use

import React from 'react';
import ReactDOM from 'react-dom';
import TelegramLoginButton from 'react-telegram-login';

const handleTelegramResponse = response => {
  console.log(response);
};

ReactDOM.render(
  <TelegramLoginButton dataOnauth={handleTelegramResponse} botName="OdauBot" />,
  document.getElementById('telegramButton')
);

Notes:

Parameters

Telegram Scopes List: https://core.telegram.org/widgets/login

dataOnauth callback

dataOnauth callback returns a TelegramUser object which provides access to all of the TelegramUser methods listed here: https://core.telegram.org/widgets/login.

dataAuthUrl redirection url

dataAuthUrl is a string which corresponds to the url where the user is redirected after a successful authorization. You should either use dataAuthUrl or dataOnauth, not both of them

Receiving authorization data

After a successful authorization, the widget can return data in two ways:

<TelegramLoginButton dataOnauth={this.handleUserInfo} botName="OdauBot" />

Dev Server

npm run start

You can set IP and PORT in webpack.config.js

Run Tests

npm run test:watch

Production Bundle

npm run bundle