From 147fd42798ec67896ba4418c53b47f9bac176c1c Mon Sep 17 00:00:00 2001 From: Blinko Date: Mon, 18 Nov 2024 15:30:39 +0800 Subject: [PATCH] fix: api auth issue --- src/pages/resources.tsx | 6 ++++-- src/server/context.ts | 2 +- src/server/trpc.ts | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/resources.tsx b/src/pages/resources.tsx index 6873201c..0ba911e3 100644 --- a/src/pages/resources.tsx +++ b/src/pages/resources.tsx @@ -14,6 +14,7 @@ import { showTipsDialog } from "@/components/Common/TipsDialog"; import { useTranslation } from "react-i18next"; import { PromiseCall } from "@/store/standard/PromiseState"; import { DialogStore } from "@/store/module/Dialog"; +import { FilesAttachmentRender } from "@/components/Common/AttachmentRender"; const Page = observer(() => { const blinko = RootStore.Get(BlinkoStore) @@ -28,7 +29,7 @@ const Page = observer(() => { blinko.resourceList.value?.map(i => { const extension = helper.getFileExtension(i.path) return - { + {/* { helper.getFileType(i.path) == 'image' ? @@ -36,7 +37,8 @@ const Page = observer(() => {
- } + } */} +
{decodeURIComponent(i.name)}
{dayjs(i.createdAt).fromNow()}
diff --git a/src/server/context.ts b/src/server/context.ts index eadd79f1..dfcc0854 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -12,7 +12,7 @@ export type User = { export async function createContext( opts: trpcNext.CreateNextContextOptions, ) { - const token = await getToken({ req: opts.req, secret: process.env.NEXTAUTH_SECRE }) as User ; + const token = await getToken({ req: opts.req, secret: process.env.NEXTAUTH_SECRE }) as User; if (!token?.sub) { return {} as User; } diff --git a/src/server/trpc.ts b/src/server/trpc.ts index d7d13033..36199c5e 100644 --- a/src/server/trpc.ts +++ b/src/server/trpc.ts @@ -23,7 +23,8 @@ export const t = initTRPC.context().meta().create({ export const router = t.router; export const publicProcedure = t.procedure; export const authProcedure = t.procedure.use(async ({ ctx, next }) => { - if (!ctx?.id) { + console.log(ctx) + if (!ctx?.name) { throw new TRPCError({ code: "UNAUTHORIZED", message: 'Unauthorized'