1.0.5 • Published 2 years ago
@use-telegram-auth/hook v1.0.5
@use-telegram-auth/hook
React hook wrapper around @use-telegram-auth/client
Installation
npm i @use-telegram-auth/hook
Usage
Using default options:
import useTelegramAuth from "@use-telegram-auth/hook";
const BOT_ID = "123";
const { onAuth, isLoading } = await useTelegramAuth(BOT_ID);
// Validate the result on server-side!
<button onClick={() => onAuth()}>
{isLoading ? "Authenticating..." : "Login"}
</button>;
Tweaking some options:
import useTelegramAuth from "@use-telegram-auth/hook";
const BOT_ID = "123";
const { onAuth, isLoading } = await useTelegramAuth(BOT_ID, {
windowFeatures: { popup: true },
});
// Validate the result on server-side!
<button onClick={() => onAuth()}>
{isLoading ? "Authenticating..." : "Login"}
</button>;
Using callbacks:
import useTelegramAuth from "@use-telegram-auth/hook";
const BOT_ID = "123";
const { onAuth, isLoading } = await useTelegramAuth(
BOT_ID,
{
windowFeatures: { popup: true },
},
{
onSuccess: (result) => {
// Send the result to the server
},
}
);
// Validate the result on server-side!
<button onClick={() => onAuth()}>
{isLoading ? "Authenticating..." : "Login"}
</button>;