Skip to content

Repository files navigation


🔐 Telegram Login for Nuxt


Documentation

  • 😌 Telegram Login - A popup button or the OpenID Connect redirect, checked on the server
  • 🔒 Sealed Sessions - One HttpOnly session cookie for every login method, no database needed
  • 🛡️ Pages and Routes - definePageMeta({ telegramAuth: true }) for pages, requireTelegramSession(event) for your API
  • 🪝 Hooks - Save users, add roles or refuse a login from a server hook

Installation:

npx nuxi module add nuxt-telegram-auth

Turn on Telegram Login for your bot in the @BotFather Mini App (Bot Settings → Login Widget), add your site to Allowed URLs, and put the client ID and a session secret in .env:

NUXT_PUBLIC_TELEGRAM_AUTH_CLIENT_ID=123456789
NUXT_APP_SECRET=at-least-32-random-characters

After that you can try it on a page:

<template>
  <div v-if="loggedIn">
    <p>Hey {{ user?.first_name }}, you are logged in!</p>
    <button @click="clear">Logout</button>
  </div>
  <TelegramLoginButton v-else />
</template>

<script setup lang="ts">
const { user, loggedIn, clear } = useTelegramSession();
</script>

See the documentation for the redirect login, hooks, page protection, the classic login widget and upgrading from 1.x.

MIT LICENSE | Halit Sever

Releases

Packages

Used by

Contributors

Languages