The `telegram-better-auth` package provides a plugin to seamlessly integrate Telegram login functionality into applications built with the `better-auth` authentication framework. This library, currently at version `0.0.8`, offers a streamlined approach to allowing users to authenticate via their Telegram accounts, managing both the server-side logic for verifying authorization data and the client-side interaction with the Telegram Login Widget. While a formal release cadence is not explicitly stated, the frequent minor version bumps (0.0.x) suggest active development. A key differentiator is its tightly coupled design with `better-auth`, abstracting complex Telegram API interactions, such as the generation of temporary emails based on Telegram IDs. Proper functioning requires a valid Telegram bot token and ensuring the bot is linked to the application's domain via BotFather.
npm install telegram-better-authVerified import paths — ran on the pinned version, not inferred.
Demonstrates both server-side and client-side setup for Telegram authentication using `telegram-better-auth` with `better-auth`. It covers plugin configuration and an example of handling authentication data from the Telegram Login Widget.
Contact @BotFather on Telegram, use the `/setdomain` command, and link your bot to the exact domain(s) where your Telegram Login Widget will be hosted.
Obtain a valid bot token from @BotFather. Set it as an environment variable (e.g., `TELEGRAM_BOT_TOKEN`) and ensure it's correctly accessed in your server-side configuration, e.g., `process.env.TELEGRAM_BOT_TOKEN ?? ''`.
Regularly review the package's GitHub repository and changelog before upgrading to new `0.0.x` versions. Consider pinning to exact versions to prevent unexpected breaking changes.
Ensure your project's Node.js environment is updated to version 20 or newer. Check your `package.json` engines field to reflect this requirement.
Ensure `telegram` plugin is added to the `plugins` array of `betterAuth` on the server and `telegramClient` plugin is added to `createAuthClient` on the client. Verify correct import paths.
Verify that the `botToken` in your server-side `telegram` plugin configuration is correct and matches the token of the bot linked to your domain. Ensure no modifications occur to the data object received from Telegram before sending it to the server.
Ensure the user re-authenticates via the Telegram Login Widget to obtain fresh `auth_date` and `hash` values. This error is typically handled by guiding the user to try logging in again.