Pārlūkot izejas kodu

🔧 chore(payment): adjust auth middleware position and add context type

- move authMiddleware from route use to createRoute middleware configuration
- add AuthContext type to OpenAPIHono for type safety
- maintain authentication functionality while improving code structure
yourname 3 nedēļas atpakaļ
vecāks
revīzija
7e05a4a913
1 mainītis faili ar 3 papildinājumiem un 2 dzēšanām
  1. 3 2
      packages/mini-payment/src/routes/payment/create.ts

+ 3 - 2
packages/mini-payment/src/routes/payment/create.ts

@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
 import { z } from 'zod';
 import { AppDataSource } from '@d8d/shared-utils';
 import { authMiddleware } from '@d8d/auth-module';
+import { AuthContext } from '@d8d/shared-types';
 import { PaymentService } from '../../services/payment.service.js';
 import { PaymentCreateRequestSchema, PaymentCreateResponseSchema } from '../../schemas/payment.schema.js';
 
@@ -9,6 +10,7 @@ import { PaymentCreateRequestSchema, PaymentCreateResponseSchema } from '../../s
 const createPaymentRoute = createRoute({
   method: 'post',
   path: '/',
+  middleware: [authMiddleware],
   request: {
     body: {
       content: {
@@ -36,8 +38,7 @@ const createPaymentRoute = createRoute({
   }
 });
 
-const app = new OpenAPIHono()
-  .use(authMiddleware)
+const app = new OpenAPIHono<AuthContext>()
   .openapi(createPaymentRoute, async (c) => {
     try {
       const paymentData = c.req.valid('json');