Skip to content

Properties

TelegramLoginWidget

The <TelegramLoginWidget> component renders the official Telegram login button.

PropTypeDefaultDescription
telegram-loginstring(required)Your bot's username (without @).
mode'callback' | 'redirect''callback'callback fires @callback on the current page. redirect sends the user to redirect-url after login.
redirect-urlstring''The URL to redirect to when mode is 'redirect'.
request-access'read' | 'write''read'Permission level requested from the user.
size'small' | 'medium' | 'large''medium'Button size.
userpicbooleantrueWhether to show the user's avatar on the button.
radiusstring'0'Border radius of the button (CSS value, e.g. '8').

Events

EventPayloadDescription
@callbackTelegramUserFired after successful login (callback mode only).
@loadednoneFired when the Telegram widget script has loaded.

Example

vue
<TelegramLoginWidget
  telegram-login="my_bot"
  size="large"
  :userpic="true"
  radius="8"
  @callback="onLogin"
  @loaded="onWidgetLoaded"
/>

useUserSession()

Composable for accessing and managing the current Telegram session.

ts
const { session, loading, error, clearSession, refresh } = useUserSession()

Return values

NameTypeDescription
sessionRef<ITelegramSession>Reactive session object. Always available; check session.loggedIn to determine auth state.
loadingRef<boolean>true while a session fetch is in progress.
errorRef<string | null>Error message if the last fetch failed, otherwise null.
clearSession()() => Promise<void>Logs the user out: calls DELETE /api/telegram/session and resets local state.
refresh()() => Promise<void>Re-fetches the session from the server.

ITelegramSession

ts
interface ITelegramSession {
  loggedIn: boolean
  status: number
  id?: number
  message?: string
  first_name?: string
  last_name?: string
  username?: string
  photo_url?: string
  auth_date?: Date
  hash?: string
}

Server Utilities

For protecting server routes, see Configuration → Protecting Server Routes.