twa-dev / SDK

npm package for TWA SDK
https://codesandbox.io/s/sdk-kj5961
MIT License
238 stars 21 forks source link

How can i use the data in server component? #21

Closed shahbaz4783 closed 2 months ago

shahbaz4783 commented 3 months ago

Im building a tg mini app, i need to get userid of telegram so i can pass it in a function to fetch data. Fetching data works in server component but we cant access user id there as it works in client component only.

is there any way i can access user id in server component??

sidewapboss commented 2 months ago

It is simple and straight same as what I did. Just catch the data on frontend, using axios post it to backend and make do with it as your application demands.

ArthurStam commented 2 months ago

The only way to pass data from Telegram SDK is to send the request (fetch/axios) from the frontend. You can't use SDK on the backend, it's frontend-only library.

sidewapboss commented 2 months ago

I'll even advise you save yourself the stress that comes with using sdk and focus on the provided variable by telegram. Try reading up on window.Telegram as that's how Telegram exposed data to mini apps