|
| 1 | +# Web3Auth (`@web3auth/modal`) Telegram React-Vite Express Example |
| 2 | + |
| 3 | +[](https://web3auth.io/docs/sdk/web) |
| 4 | +[](https://community.web3auth.io) |
| 5 | + |
| 6 | +[Join our Community Portal](https://community.web3auth.io/) to get support and stay up to date with the latest news and updates. |
| 7 | + |
| 8 | +This example demonstrates how to use Web3Auth with Telegram Login in a React Vite frontend. Express is used to create the Telegram OAuth server that issues JWT tokens for the Web3Auth SDK. |
| 9 | + |
| 10 | +## How to Use |
| 11 | + |
| 12 | +### Download Manually |
| 13 | + |
| 14 | +```bash |
| 15 | +npx degit Web3Auth/web3auth-examples/other/ton-telegram-example w3a-ton-telegram-example |
| 16 | +``` |
| 17 | + |
| 18 | +### Setup |
| 19 | + |
| 20 | +1. Create a `.env` file in the `server/api` directory with the following content: |
| 21 | + |
| 22 | +```bash |
| 23 | +TELEGRAM_BOT_NAME="" # e.g. @your_bot_name |
| 24 | +TELEGRAM_BOT_TOKEN="" # e.g. 1234567890:ABCDEF |
| 25 | +SERVER_URL="" # e.g. http://localhost:3000 |
| 26 | +CLIENT_URL="" # e.g. http://localhost:5173 |
| 27 | +JWT_KEY_ID="" # e.g. your_key_id |
| 28 | +``` |
| 29 | + |
| 30 | +2. Create a `.env.local` file in the root directory with the following content: |
| 31 | + |
| 32 | +```bash |
| 33 | +VITE_SERVER_URL="" # e.g. http://localhost:3000 |
| 34 | +VITE_W3A_VERIFIER_NAME="" # e.g. w3a-telegram-demo |
| 35 | +VITE_W3A_CLIENT_ID="" # e.g. your_client_id |
| 36 | +``` |
| 37 | + |
| 38 | +Follow [this Telegram guide](https://web3auth.io/docs/guides/telegram) to follow along. |
| 39 | + |
| 40 | +Install & Run: |
| 41 | + |
| 42 | +```bash |
| 43 | +cd w3a-example/server |
| 44 | +npm install |
| 45 | +## start server |
| 46 | +# server will be running on localhost:8080 |
| 47 | +cd api |
| 48 | +node index.js |
| 49 | +# use ngrok to expose the server to the internet |
| 50 | +# ngrok http 3000 |
| 51 | +# copy the ngrok url and update the SERVER_URL in the .env file |
| 52 | +# also update the telegram bot domain to the ngrok url |
| 53 | + |
| 54 | + |
| 55 | +## now, start the client |
| 56 | +cd .. |
| 57 | +npm install |
| 58 | +npm run start |
| 59 | +# client will be running on localhost:5173 |
| 60 | +``` |
| 61 | + |
| 62 | +## Important Links |
| 63 | + |
| 64 | +- [Website](https://web3auth.io) |
| 65 | +- [Docs](https://web3auth.io/docs) |
| 66 | +- [Guides](https://web3auth.io/docs/guides) |
| 67 | +- [SDK / API References](https://web3auth.io/docs/sdk) |
| 68 | +- [Pricing](https://web3auth.io/pricing.html) |
| 69 | +- [Community Portal](https://community.web3auth.io) |
0 commit comments