feat: add user profile fetch in middleware

This commit is contained in:
2025-12-18 08:46:50 -05:00
parent b64bd4fc26
commit 4c96f58cb0
8 changed files with 114 additions and 44 deletions

View File

@@ -2,6 +2,7 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { fetchTitleFromAnilist } from "~/libs/anilist/getTitle";
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
import { userProfileMiddleware } from "~/middleware/userProfile";
import {
AniListIdQuerySchema,
ErrorResponse,
@@ -9,6 +10,7 @@ import {
SuccessResponseSchema,
} from "~/types/schema";
import { Title } from "~/types/title";
import type { User } from "~/types/user";
const app = new OpenAPIHono();
@@ -40,6 +42,7 @@ const route = createRoute({
description: "Title could not be found",
},
},
middleware: [userProfileMiddleware],
});
app.openapi(route, async (c) => {
@@ -55,7 +58,12 @@ app.openapi(route, async (c) => {
}
const { result: title, errorOccurred } = await fetchFromMultipleSources([
() => fetchTitleFromAnilist(aniListId, aniListToken ?? undefined),
() =>
fetchTitleFromAnilist(
aniListId,
(c.get("user") as User)?.id,
aniListToken ?? undefined,
),
]);
if (errorOccurred) {