Skip to content

Commit 23cfa0b

Browse files
committed
?
1 parent 69c96a4 commit 23cfa0b

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"@react-email/components": "0.0.16",
4444
"@total-typescript/ts-reset": "^0.4.2",
4545
"@types/cookie": "^0.5.1",
46+
"@types/jsonwebtoken": "^9.0.6",
4647
"@types/pg": "^8.11.5",
48+
"@types/react": "^18.2.22",
4749
"@typescript-eslint/eslint-plugin": "^5.61.0",
4850
"@typescript-eslint/parser": "^5.61.0",
4951
"@vitest/coverage-v8": "^0.33.0",
@@ -86,8 +88,6 @@
8688
"@pothos/plugin-tracing": "^0.5.8",
8789
"@sanity/client": "^6.7.0",
8890
"@tsndr/cloudflare-worker-jwt": "^2.5.3",
89-
"@types/jsonwebtoken": "^9.0.6",
90-
"@types/react": "^18.2.22",
9191
"cookie": "^0.5.0",
9292
"dataloader": "^2.2.2",
9393
"date-fns": "^3.6.0",

src/authn/index.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sign, decode, verify } from "@tsndr/cloudflare-worker-jwt";
1+
import { decode, verify } from "@tsndr/cloudflare-worker-jwt";
22
import { Logger } from "pino";
33

44
import { TokenPayload } from "~/authn/types";
@@ -27,20 +27,6 @@ const getAuthToken = (request: Request) => {
2727
return null;
2828
};
2929

30-
export const createMinimalAuthToken = async (user: USER, SECRET: string) => {
31-
const payload = {
32-
audience: "retool",
33-
user_metadata: {
34-
sub: user.id,
35-
},
36-
exp: Date.now() + 60 * 60 * 24 * 1000 /* 24 hours */,
37-
};
38-
39-
const token = await sign(payload, SECRET);
40-
41-
return token;
42-
};
43-
4430
// Obtener el token de autorización de la solicitud, ya sea del encabezado de
4531
// autorización o de la cookie "community-os-access-token"
4632
const getImpersonatedUserFromRequest = async (

src/schema/user/mutations.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { sign } from "@tsndr/cloudflare-worker-jwt";
12
import { eq } from "drizzle-orm";
23
import { GraphQLError } from "graphql";
34

4-
import { createMinimalAuthToken } from "~/authn";
55
import { builder } from "~/builder";
66
import {
77
PronounsEnum,
88
selectUsersSchema,
99
updateUsersSchema,
10+
USER,
1011
usersSchema,
1112
usersToCommunitiesSchema,
1213
} from "~/datasources/db/schema";
@@ -19,6 +20,20 @@ import {
1920
isSameUser,
2021
} from "~/validations";
2122

23+
const createMinimalAuthToken = async (user: USER, SECRET: string) => {
24+
const payload = {
25+
audience: "retool",
26+
user_metadata: {
27+
sub: user.id,
28+
},
29+
exp: Date.now() + 60 * 60 * 24 * 1000 /* 24 hours */,
30+
};
31+
32+
const token = await sign(payload, SECRET);
33+
34+
return token;
35+
};
36+
2237
const userEditInput = builder.inputType("userEditInput", {
2338
fields: (t) => ({
2439
id: t.string({ required: true }),

0 commit comments

Comments
 (0)