Skip to content

Commit 4c00706

Browse files
committed
fix: auth plugin
1 parent 36221d7 commit 4c00706

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/templates/services/auth.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import dedent from "ts-dedent";
22

33
export function getAuthPlugin() {
44
return dedent /* ts */`
5-
import { validateAndParseInitData } from "@gramio/init-data";
6-
import { Elysia } from "elysia";
7-
import { config } from "../../config.ts";
5+
import { validateAndParseInitData, signInitData, getBotTokenSecretKey } from "@gramio/init-data";
6+
import { Elysia, t } from "elysia";
7+
import { config } from "../config.ts";
88
9+
const secretKey = getBotTokenSecretKey(config.BOT_TOKEN);
10+
911
export const authElysia = new Elysia({
1012
name: "auth",
1113
})
@@ -33,7 +35,7 @@ export function getAuthPlugin() {
3335
.resolve(({ headers, error }) => {
3436
const result = validateAndParseInitData(
3537
headers["x-init-data"],
36-
config.BOT_TOKEN
38+
secretKey
3739
);
3840
if (!result || !result.user)
3941
return error("Unauthorized", "UNAUTHORIZED");

0 commit comments

Comments
 (0)