[
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\nindent_size = 2\nindent_style = space\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.md]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".github/dependabot.yml",
    "content": "# To get started with Dependabot version updates, you'll need to specify which\n# package ecosystems to update and where the package manifests are located.\n# Please see the documentation for all configuration options:\n# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file\n\nversion: 2\nupdates:\n  - package-ecosystem: \"npm\" # See documentation for possible values\n    directory: \"/\" # Location of package manifests\n    schedule:\n      interval: \"weekly\"\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: ci\n\non:\n  push:\n    branches:\n      - main\n  pull_request:\n    branches:\n      - main\n\njobs:\n  lint:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v4\n      - run: corepack enable\n      - uses: actions/setup-node@v4\n        with:\n          node-version: 20\n\n      - name: Install dependencies\n        run: npx nypm@latest i\n\n      - name: Lint\n        run: npm run lint\n\n  test:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v4\n      - run: corepack enable\n      - uses: actions/setup-node@v4\n        with:\n          node-version: 20\n\n      - name: Install dependencies\n        run: npx nypm@latest i\n\n      - name: Prepare For Dev\n        run: npm run dev:prepare\n\n      - name: Test\n        run: npm run test\n"
  },
  {
    "path": ".github/workflows/docs.yaml",
    "content": "# Sample workflow for building and deploying a VitePress site to GitHub Pages\n#\nname: Deploy VitePress site to Pages\n\non:\n  # Runs on pushes targeting the `main` branch. Change this to `master` if you're\n  # using the `master` branch as the default branch.\n  push:\n    branches: [main]\n\n  # Allows you to run this workflow manually from the Actions tab\n  workflow_dispatch:\n\n# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages\npermissions:\n  contents: read\n  pages: write\n  id-token: write\n\n# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.\n# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.\nconcurrency:\n  group: pages\n  cancel-in-progress: false\n\njobs:\n  # Build job\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v3\n        with:\n          fetch-depth: 0 # Not needed if lastUpdated is not enabled\n      # - uses: pnpm/action-setup@v2 # Uncomment this if you're using pnpm\n      # - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun\n      - name: Setup Node\n        uses: actions/setup-node@v3\n        with:\n          node-version: 18\n          cache: npm # or pnpm / yarn\n      - name: Setup Pages\n        uses: actions/configure-pages@v5\n      - name: Install dependencies\n        run: npm ci # or pnpm install / yarn install / bun install\n      - name: Build with VitePress\n        run: |\n          npm run docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build\n          touch docs/.vitepress/dist/.nojekyll\n      - name: Upload artifact\n        uses: actions/upload-pages-artifact@v3\n        with:\n          path: docs/.vitepress/dist\n\n  # Deployment job\n  deploy:\n    environment:\n      name: github-pages\n      url: ${{ steps.deployment.outputs.page_url }}\n    needs: build\n    runs-on: ubuntu-latest\n    name: Deploy\n    steps:\n      - name: Deploy to GitHub Pages\n        id: deployment\n        uses: actions/deploy-pages@v4\n"
  },
  {
    "path": ".gitignore",
    "content": "# Dependencies\nnode_modules\n\n# Logs\n*.log*\n\n# Temp directories\n.temp\n.tmp\n.cache\n\n# Yarn\n**/.yarn/cache\n**/.yarn/*state*\n\n# Generated dirs\ndist\n\n# Nuxt\n.nuxt\n.output\n.data\n.vercel_build_output\n.build-*\n.netlify\n\n# Env\n.env\n\n# Testing\nreports\ncoverage\n*.lcov\n.nyc_output\n\n# VSCode\n.vscode/*\n!.vscode/settings.json\n!.vscode/tasks.json\n!.vscode/launch.json\n!.vscode/extensions.json\n!.vscode/*.code-snippets\n\n# Intellij idea\n*.iml\n.idea\n\n# OSX\n.DS_Store\n.AppleDouble\n.LSOverride\n.AppleDB\n.AppleDesktop\nNetwork Trash Folder\nTemporary Items\n.apdisk\n\n\n# Vitepress\n/docs/.vitepress/cache "
  },
  {
    "path": ".npmignore",
    "content": "/docs"
  },
  {
    "path": ".npmrc",
    "content": "shamefully-hoist=true\nstrict-peer-dependencies=false\n"
  },
  {
    "path": ".prettierrc",
    "content": "{\n  \"tabWidth\": 2,\n  \"useTabs\": false,\n  \"printWidth\": 220\n}\n"
  },
  {
    "path": ".vscode/settings.json",
    "content": "{\n  \"eslint.experimental.useFlatConfig\": true\n}\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\n## v1.2.6\n\n[compare changes](https://github.com/halitsever/nuxt-telegram-auth/compare/v1.2.5...v1.2.6)\n\n### 🩹 Fixes\n\n- **session.get:** Handle nullish telegram token ([bb97043](https://github.com/halitsever/nuxt-telegram-auth/commit/bb97043))\n\n### ❤️ Contributors\n\n- Halit Sever ([@halitsever](https://github.com/halitsever))\n\n## v1.2.5\n\n[compare changes](https://github.com/halitsever/nuxt-telegram-auth/compare/v1.2.4...v1.2.5)\n\n### 🩹 Fixes\n\n- Remove module options ([b721fd6](https://github.com/halitsever/nuxt-telegram-auth/commit/b721fd6))\n\n### ❤️ Contributors\n\n- Halit Sever ([@halitsever](https://github.com/halitsever))\n\n## v1.2.4\n\n[compare changes](https://github.com/halitsever/nuxt-telegram-auth/compare/v1.2.3...v1.2.4)\n\n### 📖 Documentation\n\n- Update docs workflow ([bd91510](https://github.com/halitsever/nuxt-telegram-auth/commit/bd91510))\n\n### 🏡 Chore\n\n- Upgrade dependency versions ([2765271](https://github.com/halitsever/nuxt-telegram-auth/commit/2765271))\n- Add compatibilityDate to nuxt.config ([6760493](https://github.com/halitsever/nuxt-telegram-auth/commit/6760493))\n\n### ❤️ Contributors\n\n- Halit Sever ([@halitsever](https://github.com/halitsever))\n\n## v1.2.3\n\n[compare changes](https://github.com/halitsever/nuxt-telegram-auth/compare/v1.2.2...v1.2.3)\n\n## v1.2.2\n\n[compare changes](https://github.com/halitsever/nuxt-telegram-auth/compare/v1.2.0...v1.2.2)\n\n### 🩹 Fixes\n\n- 🐛 eslint integration ([3c9754f](https://github.com/halitsever/nuxt-telegram-auth/commit/3c9754f))\n- 🐛 test workflow ([34d20d8](https://github.com/halitsever/nuxt-telegram-auth/commit/34d20d8))\n- 🐛 typo prepare:dev => dev:prepare ([da26bc3](https://github.com/halitsever/nuxt-telegram-auth/commit/da26bc3))\n- **telegramloginwidget:** Update btoa function for utf8 ([a3ce167](https://github.com/halitsever/nuxt-telegram-auth/commit/a3ce167))\n\n### 📖 Documentation\n\n- ✏️ update features section ([fc44579](https://github.com/halitsever/nuxt-telegram-auth/commit/fc44579))\n- ✏️ update features section ([fcf1c1e](https://github.com/halitsever/nuxt-telegram-auth/commit/fcf1c1e))\n- Update image aligments ([dd39167](https://github.com/halitsever/nuxt-telegram-auth/commit/dd39167))\n\n### 🏡 Chore\n\n- 🤖 add npm run lint to release script ([269ced5](https://github.com/halitsever/nuxt-telegram-auth/commit/269ced5))\n- **deps-dev:** Bump nuxt from 3.12.3 to 3.12.4 ([168e5e5](https://github.com/halitsever/nuxt-telegram-auth/commit/168e5e5))\n- **deps-dev:** Bump serve-static from 1.15.0 to 1.16.2 ([ae66e1f](https://github.com/halitsever/nuxt-telegram-auth/commit/ae66e1f))\n- **deps-dev:** Bump @types/node from 20.14.10 to 22.7.4 ([bd9663d](https://github.com/halitsever/nuxt-telegram-auth/commit/bd9663d))\n- **deps-dev:** Bump vite from 5.3.5 to 5.4.8 ([b1149f4](https://github.com/halitsever/nuxt-telegram-auth/commit/b1149f4))\n- **deps-dev:** Bump @nuxt/schema from 3.12.4 to 3.13.2 ([1c62687](https://github.com/halitsever/nuxt-telegram-auth/commit/1c62687))\n- **deps-dev:** Bump eslint from 9.6.0 to 9.12.0 ([3418ff4](https://github.com/halitsever/nuxt-telegram-auth/commit/3418ff4))\n- **deps-dev:** Bump vitest from 1.6.0 to 2.1.2 ([3bb8589](https://github.com/halitsever/nuxt-telegram-auth/commit/3bb8589))\n- **deps-dev:** Bump rollup from 3.29.4 to 3.29.5 ([7551df1](https://github.com/halitsever/nuxt-telegram-auth/commit/7551df1))\n- **deps-dev:** Bump vue-tsc from 2.0.26 to 2.1.6 ([4340bea](https://github.com/halitsever/nuxt-telegram-auth/commit/4340bea))\n- **package.json:** Bump nuxt to 3.17.1 ([d4e28b5](https://github.com/halitsever/nuxt-telegram-auth/commit/d4e28b5))\n\n### ❤️ Contributors\n\n- Halit Sever ([@halitsever](http://github.com/halitsever))\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2024 Halit Sever\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\" class=\"logo-section\">\n<img src=\"https://i.ibb.co/MMcBdPN/nuxt-telegram-auth.png\" height=\"80\" width=\"80\"/>\n</br>\n<img src=\"https://halitsever-api.vercel.app/api/repo-title?title=Nuxt%20Telegram%20Auth\">\n\n<p align=\"center\">\n🔐 A telegram login widget integration for nuxt 3\n<br>\n<br/>\n<br/>\n<img src=\"https://img.shields.io/github/sponsors/halitsever\"/>\n</p>\n<p align=\"center\">\n<a align=\"center\" href=\"https://halitsever.github.io/nuxt-telegram-auth\">Documentation</a>\n  </p>\n</p>\n\n<p align=\"center\">\n<img src=\"https://halitsever-api.vercel.app/api/details\"/>\n</p>\n\n- 😌 [**Easy Integration**](#) - A telegram bot and this module enough for telegram login widget\n- 🔒 [**Auth Endpoint**](#) - Nuxt Telegram Module provides a api endpoint for checking is user's cookie valid or not: /api/telegram/session, this method integrated from official <a href=\"https://gist.github.com/anonymous/6516521b1fb3b464534fbc30ea3573c2\">example php code</a>\n  <p align=\"center\" >\n  <img src=\"https://halitsever-api.vercel.app/api/installation\"/>\n  </p>\n\nInstallation:\n\n```bash\nnpx nuxi module add nuxt-telegram-auth\n```\n\nThen you need add TELEGRAM_TOKEN to your runtimeConfig:\n\n```javascript\nruntimeConfig: {\n  TELEGRAM_TOKEN: \"my_fancy_bot_token\",\n}\n```\n\nafter that you can try on a page:\n\n```javascript\n\n<template>\n  <div>\n    <div>\n      <div v-if=\"session.loggedIn\">\n        <NuxtLink @click=\"logout\" to=\"/\">Logout</NuxtLink>\n        <a>Hey you are logged in!</a>\n        <p>Session: {{ session }}</p>\n      </div>\n      <div v-else>\n        <TelegramLoginWidget telegram-login=\"my_bot\" @callback=\"testCallback\" />\n      </div>\n    </div>\n  </div>\n</template>\n\n<script setup>\nconst { clearSession, session } = useUserSession();\nconst logout = () => clearSession();\nconst testCallback = (user) => {\n  console.log(\"Custom callback function: \",user);\n};\n</script>\n```\n\nfor more detailed information, please check the documentation page.\n\n<p align=\"center\" href=\"https://github.com/halitsever/nuxt-telegram-auth/issues\">\n<img src=\"https://halitsever-api.vercel.app/api/issue\"/>\n</p>\n\n<p align=\"center\">\n<img src=\"https://halitsever-api.vercel.app/api/sponsor\"/>\n</p>\n\n<p align=\"center\">\n<img src=\"https://halitsever-api.vercel.app/api/license\"/>\n</p>\n\n<p align=\"center\">\n  MIT LICENSE | <a href=\"https://halit.org\">Halit Sever</a>\n</p>\n"
  },
  {
    "path": "docs/.vitepress/config.ts",
    "content": "import { defineConfig } from \"vitepress\";\n\n// https://vitepress.dev/reference/site-config\nexport default defineConfig({\n  title: \"Nuxt Telegram Auth\",\n  description: \"Effortlessly integrate the Telegram login widget into your Nuxt 3 application with our easy-to-use npm package, enhancing user authentication and engagement.\",\n\n  base: \"/nuxt-telegram-auth/\",\n\n  themeConfig: {\n    // https://vitepress.dev/reference/default-theme-config\n    nav: [\n      { text: \"Home\", link: \"/\" },\n      { text: \"Quick Start\", link: \"/installation\" },\n    ],\n\n    sidebar: [\n      {\n        text: \"Documentation\",\n        items: [\n          { text: \"Quickstart\", link: \"/installation\" },\n          { text: \"Properties\", link: \"/properties\" },\n        ],\n      },\n    ],\n\n    socialLinks: [{ icon: \"github\", link: \"https://github.com/halitsever/nuxt-telegram-auth\" }],\n  },\n});\n"
  },
  {
    "path": "docs/index.md",
    "content": "---\n# https://vitepress.dev/reference/default-theme-home-page\nlayout: home\n\nhero:\n  name: \"Nuxt Telegram Auth\"\n\n  tagline: 🔐 Telegram login widget integration for Nuxt 3\n  actions:\n    - theme: brand\n      text: Documentation\n      link: /installation\n    - theme: alt\n      text: Github\n      link: https://github.com/halitsever/nuxt-telegram-auth\n  image:\n    src: /telegram-logo.png\n    alt: Nuxt Telegram Auth\n---\n"
  },
  {
    "path": "docs/installation.md",
    "content": "# Installation\n\nFirst of all you need a telegram bot, if you don't know to how to create a telegram bot please check this <a href=\"https://core.telegram.org/bots#how-do-i-create-a-bot\">link</a>.\n\n# Step 1:\n\nInstall the module:\n\n```bash\nnpx nuxi module add nuxt-telegram-auth\n```\n\n# Step 2:\n\nYou need grab bot token from telegram, you can get your bot's token from Bot_Father:\n<img src=\"/telegram-token.png\"/>\n\nThen add your nuxt.config.ts file:\n\n```javascript\nruntimeConfig: {\n  TELEGRAM_TOKEN: \"my_fancy_bot_token\",\n}\n```\n\nalso you need allow your domain on Bot_Father otherwise you will get \"Invalid Domain\" error.\n\n<img src=\"/domain.png\"/>\n\nAfter that you can use `TelegramLoginWidget` component:\n\n```javascript\n<template>\n  <div>\n    <div>\n      <div v-if=\"session.loggedIn\">\n        <NuxtLink @click=\"logout\" to=\"/\">Logout</NuxtLink>\n        <a>Hey you are logged in!</a>\n        <p>Session: {{ session }}</p>\n      </div>\n      <div v-else>\n        <TelegramLoginWidget telegram-login=\"my_bot\" @callback=\"testCallback\" />\n      </div>\n    </div>\n  </div>\n</template>\n\n<script setup>\nconst { clearSession, session } = useUserSession();\nconst logout = () => clearSession();\nconst testCallback = (user) => {\n  console.log(\"Custom callback function: \",user);\n};\n</script>\n```\n\n`telegram-login` value should be your bot's name.\n\n`@callback` emit is optional.\n"
  },
  {
    "path": "docs/properties.md",
    "content": "# Not documented for now\n"
  },
  {
    "path": "eslint.config.mjs",
    "content": "// @ts-check\nimport { createConfigForNuxt } from \"@nuxt/eslint-config/flat\";\n\n// Run `npx @eslint/config-inspector` to inspect the resolved config interactively\nexport default createConfigForNuxt({\n  features: {\n    // Rules for module authors\n    tooling: true,\n    // Rules for formatting\n    stylistic: false,\n  },\n\n  dirs: {\n    src: [\"./playground\"],\n  },\n}).append([\n  {\n    ignores: [\"docs/*\"],\n  },\n]);\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"nuxt-telegram-auth\",\n  \"version\": \"1.2.6\",\n  \"description\": \"🔐 Telegram login widget integration for Nuxt 3\",\n  \"repository\": \"https://github.com/halitsever/nuxt-telegram-auth.git\",\n  \"license\": \"MIT\",\n  \"type\": \"module\",\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/module.mjs\"\n    }\n  },\n  \"main\": \"./dist/module.mjs\",\n  \"files\": [\n    \"dist\"\n  ],\n  \"scripts\": {\n    \"prepack\": \"nuxt-module-build build\",\n    \"dev\": \"nuxi dev playground --host\",\n    \"dev:build\": \"nuxi build playground\",\n    \"dev:prepare\": \"nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground\",\n    \"release\": \"npm run lint && npm run prettier && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags\",\n    \"lint\": \"eslint .\",\n    \"prettier\": \"prettier --write .\",\n    \"test\": \"vitest run\",\n    \"test:watch\": \"vitest watch\",\n    \"test:types\": \"vue-tsc --noEmit && cd playground && vue-tsc --noEmit\",\n    \"docs:dev\": \"vitepress dev docs\",\n    \"docs:build\": \"vitepress build docs\",\n    \"docs:preview\": \"vitepress preview docs\"\n  },\n  \"dependencies\": {\n    \"@nuxt/kit\": \"^3.17.4\"\n  },\n  \"devDependencies\": {\n    \"@nuxt/devtools\": \"^2.4.1\",\n    \"@nuxt/eslint-config\": \"^1.4.1\",\n    \"@nuxt/module-builder\": \"^1.0.1\",\n    \"@nuxt/schema\": \"^3.17.4\",\n    \"@nuxt/test-utils\": \"^3.19.1\",\n    \"@types/node\": \"^22.15.21\",\n    \"changelogen\": \"^0.6.1\",\n    \"eslint\": \"^9.27.0\",\n    \"nuxt\": \"^3.17.4\",\n    \"prettier\": \"^3.5.3\",\n    \"typescript\": \"latest\",\n    \"vitepress\": \"^1.6.3\",\n    \"vitest\": \"^3.1.4\",\n    \"vue-tsc\": \"^2.2.10\"\n  },\n  \"optionalDependencies\": {\n    \"@rollup/rollup-linux-x64-gnu\": \"^4.41.1\"\n  }\n}\n"
  },
  {
    "path": "playground/app.vue",
    "content": "<template>\n  <div>\n    <div>\n      <div v-if=\"session.loggedIn\">\n        <button @click=\"logout\">Logout</button>\n        <a>Hey you are logged in!</a>\n        <p>Session: {{ session }}</p>\n      </div>\n      <div v-else>\n        <TelegramLoginWidget telegram-login=\"my_bot\" @callback=\"testCallback\" />\n      </div>\n    </div>\n  </div>\n</template>\n\n<script setup>\nconst { clearSession, session } = useUserSession();\nconst logout = () => clearSession();\nconst testCallback = (user) => {\n  console.log(\"Custom callback function: \", user);\n};\n</script>\n"
  },
  {
    "path": "playground/nuxt.config.ts",
    "content": "export default defineNuxtConfig({\n  modules: [\"../src/module\"],\n  devtools: { enabled: true },\n  compatibilityDate: \"2025-05-26\",\n  runtimeConfig: {\n    TELEGRAM_TOKEN: \"my_fancy_bot_token\",\n  },\n});\n"
  },
  {
    "path": "playground/package.json",
    "content": "{\n  \"private\": true,\n  \"name\": \"nuxt-telegram-auth-playground\",\n  \"type\": \"module\",\n  \"scripts\": {\n    \"dev\": \"nuxi dev\",\n    \"build\": \"nuxi build\",\n    \"generate\": \"nuxi generate\"\n  },\n  \"dependencies\": {\n    \"nuxt\": \"^3.16.0\"\n  }\n}\n"
  },
  {
    "path": "playground/server/tsconfig.json",
    "content": "{\n  \"extends\": \"../.nuxt/tsconfig.server.json\"\n}\n"
  },
  {
    "path": "playground/tsconfig.json",
    "content": "{\n  \"extends\": \"./.nuxt/tsconfig.json\"\n}\n"
  },
  {
    "path": "src/module.ts",
    "content": "import { defineNuxtModule, createResolver, addComponent, addServerHandler, addImportsDir } from \"@nuxt/kit\";\n\nexport default defineNuxtModule({\n  meta: {\n    name: \"nuxt-telegram-auth\",\n    configKey: \"telegramAuth\",\n  },\n\n  defaults: {},\n  setup(_options, _nuxt) {\n    const resolver = createResolver(import.meta.url);\n\n    addImportsDir(resolver.resolve(\"./runtime/app/composables\"));\n\n    addComponent({\n      name: \"TelegramLoginWidget\",\n      filePath: resolver.resolve(\"runtime/components/TelegramLoginWidget.vue\"),\n    });\n\n    addServerHandler({\n      handler: resolver.resolve(\"runtime/server/api/telegram/session.get\"),\n      route: \"/api/telegram/session\",\n      method: \"get\",\n    });\n\n    addServerHandler({\n      handler: resolver.resolve(\"runtime/server/api/telegram/session.delete\"),\n      route: \"/api/telegram/session\",\n      method: \"delete\",\n    });\n  },\n});\n"
  },
  {
    "path": "src/runtime/app/composables/session.ts",
    "content": "import { useAsyncData, useRequestFetch, useState } from \"nuxt/app\";\nimport type { ITelegramSession, IUserSession } from \"../../types/session\";\n\nexport const useSessionState = () => useState(\"telegram-session\", () => ({}));\n\nexport function useUserSession(): IUserSession {\n  fetchSession();\n  const session = useSessionState();\n  return { session, clearSession };\n}\n\nexport const clearSession = async () => {\n  await $fetch(\"/api/telegram/session\", { method: \"DELETE\" });\n  useSessionState().value = { loggedIn: false };\n};\n\nexport const fetchSession = async () => {\n  const sessionState = useSessionState();\n  const { data } = await useAsyncData<ITelegramSession>(\"telegram_auth\", () => useRequestFetch()(\"/api/telegram/session\"));\n  sessionState.value = data;\n};\n"
  },
  {
    "path": "src/runtime/components/TelegramLoginWidget.vue",
    "content": "<template>\n  <div id=\"telegram\" />\n</template>\n\n<script setup>\nimport { onMounted } from \"vue\";\nimport { fetchSession } from \"../app/composables/session\";\nimport { useCookie } from \"#app\";\n\nconst props = defineProps({\n  mode: {\n    type: String,\n    default: \"callback\",\n  },\n  telegramLogin: {\n    type: String,\n    required: true,\n  },\n  redirectUrl: {\n    type: String,\n    default: \"\",\n  },\n  requestAccess: {\n    type: String,\n    default: \"read\",\n  },\n  size: {\n    type: String,\n    default: \"medium\",\n  },\n  userpic: {\n    type: Boolean,\n    default: true,\n  },\n  radius: {\n    default: \"0\",\n    type: String,\n  },\n});\n\nconst emit = defineEmits([\"callback\", \"loaded\"]);\n\nconst userCookie = useCookie(\"tg_user\", {\n  maxAge: 60 * 60 * 24,\n  secure: process.env.NODE_ENV === \"production\",\n  sameSite: \"lax\",\n});\n\nconst setCookie = (payload) => {\n  userCookie.value = btoa(String.fromCharCode(...new TextEncoder(\"utf-8\").encode(JSON.stringify(payload))));\n};\n\nfunction onTelegramAuth(payload) {\n  setCookie(payload);\n  fetchSession();\n  emit(\"callback\", payload);\n}\n\nonMounted(() => {\n  if (import.meta.client) {\n    const script = document.createElement(\"script\");\n    script.async = true;\n    script.src = \"https://telegram.org/js/telegram-widget.js?3\";\n\n    script.setAttribute(\"data-telegram-login\", props.telegramLogin);\n    script.setAttribute(\"data-request-access\", props.requestAccess);\n    script.setAttribute(\"data-size\", props.size);\n    script.setAttribute(\"data-userpic\", props.userpic);\n\n    if (props.radius) script.setAttribute(\"data-radius\", props.radius);\n\n    if (props.mode === \"callback\") {\n      window.onTelegramAuth = onTelegramAuth;\n      script.setAttribute(\"data-onauth\", \"window.onTelegramAuth(user)\");\n    } else {\n      script.setAttribute(\"data-auth-url\", props.redirectUrl);\n    }\n\n    document.querySelector(\"#telegram\").appendChild(script);\n    emit(\"loaded\");\n  }\n});\n</script>\n"
  },
  {
    "path": "src/runtime/server/api/telegram/session.delete.ts",
    "content": "import { eventHandler, deleteCookie } from \"h3\";\n\nexport default eventHandler(async (event) => {\n  try {\n    deleteCookie(event, \"tg_user\");\n    return { status: 200, message: \"Session Deleted\" };\n  } catch (err) {\n    console.error(\"Telegram Auth - \", err);\n    return { status: 500, message: \"Interval Server Error\" };\n  }\n});\n"
  },
  {
    "path": "src/runtime/server/api/telegram/session.get.ts",
    "content": "import { eventHandler, getCookie } from \"h3\";\n// @ts-expect-error nitro aliases aren't registered\nimport { useRuntimeConfig } from \"#internal/nitro\";\nimport * as crypto from \"node:crypto\";\n\nconst handleUnauthorized = () => {\n  return {\n    loggedIn: false,\n    status: 401,\n    message: \"Unauthorized\",\n  };\n};\n\nexport default eventHandler(async (event) => {\n  try {\n    const session = getCookie(event, \"tg_user\");\n\n    const runtimeConfig = useRuntimeConfig(event);\n\n    if (!session) return handleUnauthorized();\n\n    const decodedCookie = JSON.parse(Buffer.from(session, \"base64\").toString(\"utf-8\"));\n\n    if (Date.now() / 1000 - decodedCookie.auth_date > 86400) return handleUnauthorized();\n\n    const telegramApiToken = runtimeConfig.TELEGRAM_TOKEN;\n\n    if (!telegramApiToken) return {\n      loggedIn: false,\n      status: 500,\n      body: \"Telegram bot token is not configured\",\n    };\n\n    const secret = crypto.createHash(\"sha256\").update(telegramApiToken).digest();\n\n    /*\n        This part creates a data-check-string in here as referred in documentation\n        and then it checks on the server side if the hash is correct.\n        Docs: https://core.telegram.org/widgets/login#checking-authorization\n    */\n\n    const dataCheckString = [];\n    for (const key in decodedCookie) if (key != \"hash\") dataCheckString.push(key + \"=\" + decodedCookie[key]);\n\n    const check_hash = crypto.createHmac(\"sha256\", secret).update(dataCheckString.sort().join(\"\\n\")).digest(\"hex\");\n\n    return {\n      loggedIn: check_hash == decodedCookie.hash,\n      ...decodedCookie,\n    };\n  } catch (err) {\n    console.error(\"Telegram Auth - \", err);\n    return {\n      loggedIn: false,\n      status: 500,\n      body: \"Internal Server Error\",\n    };\n  }\n});\n"
  },
  {
    "path": "src/runtime/server/tsconfig.json",
    "content": "{\n  \"extends\": \"../../../.nuxt/tsconfig.server.json\"\n}\n"
  },
  {
    "path": "src/runtime/types/session.ts",
    "content": "import type { Ref } from \"vue\";\n\nexport interface ITelegramSession {\n  loggedIn: boolean;\n  status: number;\n  id?: number;\n  message?: string;\n  first_name?: string;\n  username?: string;\n  photo_url?: string;\n  auth_date?: Date;\n  hash?: string;\n}\n\nexport interface IUserSession {\n  session: ITelegramSession | Ref<null>;\n  clearSession: () => Promise<void>;\n}\n"
  },
  {
    "path": "test/basic.test.ts",
    "content": "import { fileURLToPath } from \"node:url\";\nimport { describe, it, expect } from \"vitest\";\nimport { setup, $fetch } from \"@nuxt/test-utils/e2e\";\n\ndescribe(\"ssr\", async () => {\n  await setup({\n    rootDir: fileURLToPath(new URL(\"./fixtures/basic\", import.meta.url)),\n  });\n\n  it(\"renders the index page\", async () => {\n    // Get response to a server-rendered page with `$fetch`.\n    const html = await $fetch(\"/\");\n    expect(html).toContain(\"<div>basic</div>\");\n  });\n});\n"
  },
  {
    "path": "test/fixtures/basic/app.vue",
    "content": "<template>\n  <div>basic</div>\n</template>\n\n<script setup></script>\n"
  },
  {
    "path": "test/fixtures/basic/nuxt.config.ts",
    "content": "import NuxtTelegramAuth from \"../../../src/module\";\n\nexport default defineNuxtConfig({\n  modules: [NuxtTelegramAuth],\n});\n"
  },
  {
    "path": "test/fixtures/basic/package.json",
    "content": "{\n  \"private\": true,\n  \"name\": \"basic\",\n  \"type\": \"module\"\n}\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"extends\": \"./.nuxt/tsconfig.json\",\n  \"exclude\": [\"dist\", \"node_modules\", \"playground\"]\n}\n"
  }
]