Skip to content

Commit ad7d0dd

Browse files
fix: telegram plugin fixes
1 parent 3d96371 commit ad7d0dd

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backend",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "PoliNetwork backend server",
55
"private": true,
66
"keywords": [],

backend/src/auth/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { db } from "@/db/db";
44
import { SCHEMA } from "@/db";
55
import { env } from "@/env";
66
import { AUTH_PATH } from "@/constants";
7+
import { telegramPlugin } from "./plugins/telegram";
78

89
export const auth = betterAuth({
910
basePath: AUTH_PATH,
1011
baseURL: env.PUBLIC_URL,
1112
trustedOrigins: env.TRUSTED_ORIGINS,
13+
plugins: [telegramPlugin()],
1214
database: drizzleAdapter(db, {
1315
provider: "pg",
1416
schema: {

backend/src/auth/plugins/telegram/index.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DB, SCHEMA } from "@/db";
2-
import { z, type BetterAuthPlugin } from "better-auth";
3-
import { createAuthEndpoint } from "better-auth/api";
2+
import { type BetterAuthPlugin } from "better-auth";
3+
import { z } from "zod";
4+
import { createAuthEndpoint, sessionMiddleware } from "better-auth/api";
45
import crypto from "crypto";
56
import { eq } from "drizzle-orm";
67

@@ -36,6 +37,8 @@ export const telegramPlugin = () => {
3637
"/telegram/link/start",
3738
{
3839
method: "POST",
40+
use: [sessionMiddleware],
41+
body: linkBody
3942
},
4043
async (ctx) => {
4144
const userId = ctx.context.session?.user.id;
@@ -44,14 +47,7 @@ export const telegramPlugin = () => {
4447
message: "You must be authenticated",
4548
});
4649

47-
const { data, success } = linkBody.safeParse(ctx.body);
48-
if (!success)
49-
return ctx.error("BAD_REQUEST", {
50-
message:
51-
"'telegramUsername' must be provided and must be a string",
52-
});
53-
54-
const { telegramUsername } = data;
50+
const { telegramUsername } = ctx.body;
5551
const [{ code, ttl }] = await DB.insert(SCHEMA.TG.link)
5652
.values({
5753
code: crypto
@@ -73,6 +69,7 @@ export const telegramPlugin = () => {
7369
"/telegram/link/verify/:code",
7470
{
7571
method: "GET",
72+
use: [sessionMiddleware]
7673
},
7774
async (ctx) => {
7875
const userId = ctx.context.session?.user.id;

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polinetwork/backend",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "Utils to interact with the backend.",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)