diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index eb9551c1d..eaaefd4b2 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -10,13 +10,13 @@ import { Hono } from "hono"; import { cors } from "hono/cors"; import { container } from "tsyringe"; -import { AuthInterceptor } from "@src/auth/services/auth.interceptor"; import { config } from "@src/core/config"; import { getSentry, sentryOptions } from "@src/core/providers/sentry.provider"; import { HonoErrorHandlerService } from "@src/core/services/hono-error-handler/hono-error-handler.service"; import { HttpLoggerService } from "@src/core/services/http-logger/http-logger.service"; import { LoggerService } from "@src/core/services/logger/logger.service"; import { RequestContextInterceptor } from "@src/core/services/request-storage/request-context.interceptor"; +import { HonoInterceptor } from "@src/core/types/hono-interceptor.type"; import packageJson from "../package.json"; import { chainDb, syncUserSchema, userDb } from "./db/dbConnection"; import { apiRouter } from "./routers/apiRouter"; @@ -49,7 +49,6 @@ const scheduler = new Scheduler({ appHono.use(container.resolve(HttpLoggerService).intercept()); appHono.use(container.resolve(RequestContextInterceptor).intercept()); -appHono.use(container.resolve(AuthInterceptor).intercept()); appHono.use( "*", sentry({ @@ -70,6 +69,9 @@ appHono.route("/internal", internalRouter); // TODO: remove condition once billing is in prod if (BILLING_ENABLED === "true") { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { AuthInterceptor } = require("./auth/services/auth.interceptor"); + appHono.use(container.resolve(AuthInterceptor).intercept()); // eslint-disable-next-line @typescript-eslint/no-var-requires const { createWalletRouter, getWalletListRouter, signAndBroadcastTxRouter } = require("./billing"); appHono.route("/", createWalletRouter); diff --git a/apps/api/src/routers/userRouter.ts b/apps/api/src/routers/userRouter.ts index 696fc1e9f..de1f9a591 100644 --- a/apps/api/src/routers/userRouter.ts +++ b/apps/api/src/routers/userRouter.ts @@ -3,7 +3,6 @@ import assert from "http-assert"; import { container } from "tsyringe"; import * as uuid from "uuid"; -import { AuthTokenService } from "@src/auth/services/auth-token/auth-token.service"; import { getCurrentUserId, optionalUserMiddleware, requiredUserMiddleware } from "@src/middlewares/userMiddleware"; import { addTemplateFavorite, @@ -132,10 +131,16 @@ userRequiredRouter.post("/tokenInfo", async c => { }); async function extractAnonymousUserId(c: Context) { + if (process.env.BILLING_ENABLED !== "true") { + return; + } + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { AuthTokenService } = require("@src/auth/services/auth-token/auth-token.service"); + const anonymousBearer = c.req.header("x-anonymous-authorization"); if (anonymousBearer) { - const anonymousUserId = await container.resolve(AuthTokenService).getValidUserId(anonymousBearer); + const anonymousUserId = await container.resolve(AuthTokenService).getValidUserId(anonymousBearer); assert(anonymousUserId, 401, "Invalid anonymous user token"); return anonymousUserId;