Registry / messaging / tg-auth

tg-auth

JSON →
library1.0.1jsnpmunverified

Telegram 登录授权 Vue 组件,支持 H5 和 uni-app App 环境。当前版本 1.0.1,通过 iframe 或跳转系统浏览器实现 Telegram Login Widget,需配合静态授权页部署。与官方 Telegram Login Widget 相比,提供更便捷的 Vue 集成、自动检测运行时环境、支持自定义样式 slot、以及针对 uni-app 的深链回调机制,并附带辅助函数解析授权结果。

npm install tg-auth
INSTALL
IMPORT
SIG · TG-AUTH
T
tg-auth
messagingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TgAuth
import { TgAuth } from 'tg-auth'
import TgAuth from 'tg-auth'
The library exports TgAuth as a named export, not a default export.
TG_AUTH_RESULT_REGEX
import { TG_AUTH_RESULT_REGEX } from 'tg-auth'
import TG_AUTH_RESULT_REGEX from 'tg-auth'
Exported as a named constant, not default.
parseTgAuthResult
import { parseTgAuthResult } from 'tg-auth'
import { parseTgAuthResult } from 'tg-auth/utils'
All exports are from the main package entry; there is no utils subpath.

Registers the TgAuth component globally in a Vue 3 app, then use in template with required props.

import { createApp } from 'vue'; import App from './App.vue'; import { TgAuth } from 'tg-auth'; createApp(App).component('TgAuth', TgAuth).mount('#app');
Debug
Known issues
gotchaOn uni-app App side (when window === undefined), the authorized event is NOT emitted. Authorization result must be obtained by parsing URL "arg" parameter from the deep link callback.
fix
Implement URL parsing in the App entry to extract the 'arg' parameter from the incoming deep link.
affects: >=1.0.0
gotchaThe static authorization page must be copied to the host project and deployed at the tgAuthDomain origin. If not deployed correctly, the authorization will fail silently.
fix
Run `npx tg-auth-copy-static --target <path>` and ensure the domain in BotFather matches the deployed origin.
affects: >=1.0.0
gotchaThe `bot-id` prop must be a string even if it's numeric; passing a number may cause type issues in Vue template.
fix
Explicitly convert the bot ID to a string: :bot-id="String(botId)".
affects: >=1.0.0
deprecatedThe component uses Vue 3 only; Vue 2 is not supported.
fix
Upgrade to Vue 3 or use an alternative Telegram auth solution.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'value')
Using TgAuth without providing the required bot-id or tg-auth-domain props.
fix
Ensure both props are provided: <TgAuth :tg-auth-domain="'https://example.com'" :bot-id="'123456789'" />
Error: Static page not found at /static/html/tgauth-h5.html
Did not run the copy-static script or deployed to wrong path.
fix
Run `npx tg-auth-copy-static --target public/static/html` and verify the file exists at the expected URL.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
vueoptionalpeer dependency: requires Vue 3 for component functionality
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
tg-auth — npm install tg-auth · libregistry