File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -96,8 +96,14 @@ console.log(initData.hash); // Хэш для проверки
9696` examples ` в ` x-init-data ` заголовке являются валидными сгенерированными ` init-data ` , которые позволяют легче тестировать ваш API в OpenAPI клиентах.
9797
9898``` ts twoslash
99- import { validateAndParseInitData } from " @gramio/init-data" ;
100- import { Elysia } from " elysia" ;
99+ import {
100+ validateAndParseInitData ,
101+ signInitData ,
102+ getBotTokenSecretKey ,
103+ } from " @gramio/init-data" ;
104+ import { Elysia , t } from " elysia" ;
105+
106+ const secretKey = getBotTokenSecretKey (process .env .BOT_TOKEN as string );
101107
102108export const authElysia = new Elysia ({
103109 name: " auth" ,
@@ -126,7 +132,7 @@ export const authElysia = new Elysia({
126132 .resolve (({ headers , error }) => {
127133 const result = validateAndParseInitData (
128134 headers [" x-init-data" ],
129- config . BOT_TOKEN
135+ secretKey
130136 );
131137 if (! result || ! result .user )
132138 return error (" Unauthorized" , " UNAUTHORIZED" );
Original file line number Diff line number Diff line change @@ -31,8 +31,14 @@ This example shows how to integrate `@gramio/init-data` with Elysia via convenie
3131` examples ` at ` x-init-data ` header is valid generated init-data which allows you to more easily test your API in OpenAPI Client.
3232
3333``` ts twoslash
34- import { validateAndParseInitData } from " @gramio/init-data" ;
35- import { Elysia } from " elysia" ;
34+ import {
35+ validateAndParseInitData ,
36+ signInitData ,
37+ getBotTokenSecretKey ,
38+ } from " @gramio/init-data" ;
39+ import { Elysia , t } from " elysia" ;
40+
41+ const secretKey = getBotTokenSecretKey (process .env .BOT_TOKEN as string );
3642
3743export const authElysia = new Elysia ({
3844 name: " auth" ,
@@ -61,7 +67,7 @@ export const authElysia = new Elysia({
6167 .resolve (({ headers , error }) => {
6268 const result = validateAndParseInitData (
6369 headers [" x-init-data" ],
64- config . BOT_TOKEN
70+ secretKey
6571 );
6672 if (! result || ! result .user )
6773 return error (" Unauthorized" , " UNAUTHORIZED" );
You can’t perform that action at this time.
0 commit comments