Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Not clear documentation on init-data-node package, can't configure end to end validation #467

Open
hubert-de-lalye opened this issue Sep 9, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@hubert-de-lalye
Copy link

Is your feature request related to a problem? Please describe.

Not quite sure what kind of issue to open, bug or feature. I'm kinda sure that I'm doing something wrong, but have no idea what exactly. Currently I'm struggling with validation with init-data-node package. Constantly get Signature is invalid whatever I try to pass to validate.

I see some differences between documentation and real life. For instance the user data passed as encoded URI component in example has format user_name: '...', but useInitData() returns userName: '...'. Additionally, if look into .validate() implementation it seems that ordering in user data JSON should be important.

I tried to pass URI, to pass result of useInitData() but any option returned me a Signature is invalid. Currently me approach is to pass decodeURIComponent(window.location.hash.replace("#tgWebAppData=", "")) to NodeJS, then use parseInitData on it and pass result to .validate. I run out of ideas what else am I doing wrong. Some help will be very useful and appreciated

Describe the solution you'd like

Add an end to end example or more detailed description of how to get data on client side and pass it to NodeJS including formats, ordering etc

Describe alternatives you've considered

No response

Additional context

No response

@hubert-de-lalye hubert-de-lalye added the enhancement New feature or request label Sep 9, 2024
@heyqbnk
Copy link
Member

heyqbnk commented Sep 10, 2024

Hey! If you are using @telegram-apps/sdk-react, you must use useLaunchParams().initDataRaw. useInitData() returns an object based on the raw representation, but it may cut some fields or mutate values for more comfortable usage.

Think of the useInitData result as an object with just some picked and typed values from the raw representation. You can't use it to pass to the server side

@hubert-de-lalye
Copy link
Author

Wow, seems works for me. I think it will be great to explicitly highlight this in documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants