Merge branch 'feature/auth'
This commit is contained in:
@@ -15,26 +15,31 @@ export async function createMerchant(body: CreateMerchantBody) {
|
||||
const apiKey = generateApiKey()
|
||||
const secretKey = generateSecretKey()
|
||||
|
||||
// Insert new merchant
|
||||
const result = await db
|
||||
.insert(table.merchants)
|
||||
.values({
|
||||
merchantName: body.merchantName,
|
||||
contactEmail: body.contactEmail,
|
||||
contactPhone: body.contactPhone,
|
||||
apiKey,
|
||||
secretKey,
|
||||
})
|
||||
.returning({
|
||||
merchantId: table.merchants.merchantId,
|
||||
apiKey: table.merchants.apiKey,
|
||||
secretKey: table.merchants.secretKey,
|
||||
createdAt: table.merchants.createdAt,
|
||||
})
|
||||
try {
|
||||
// Insert new merchant
|
||||
const result = await db
|
||||
.insert(table.merchants)
|
||||
.values({
|
||||
merchantName: body.merchantName,
|
||||
contactEmail: body.contactEmail,
|
||||
contactPhone: body.contactPhone,
|
||||
apiKey,
|
||||
secretKey,
|
||||
})
|
||||
.returning({
|
||||
merchantId: table.merchants.merchantId,
|
||||
apiKey: table.merchants.apiKey,
|
||||
secretKey: table.merchants.secretKey,
|
||||
createdAt: table.merchants.createdAt,
|
||||
})
|
||||
|
||||
if (result.length === 0) {
|
||||
if (result.length === 0) {
|
||||
throw new Error('Failed to create merchant')
|
||||
}
|
||||
|
||||
return result[0]
|
||||
} catch (error) {
|
||||
console.error('Error creating merchant:', error)
|
||||
throw new Error('Failed to create merchant')
|
||||
}
|
||||
|
||||
return result[0]
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createMerchantBody, createMerchantResponseSchema } from './schema'
|
||||
import CreateMerchantService from './commands/service'
|
||||
import { basicAuthMiddleware } from '~/middlewares/basicAuth'
|
||||
import { DataAlreadyExistsError } from '~/helpers/errors'
|
||||
import { apiKeyAuth } from '~/middlewares/apiKeyAuth'
|
||||
|
||||
export const router = new Elysia({
|
||||
name: 'modules.auth',
|
||||
@@ -40,5 +41,14 @@ export const router = new Elysia({
|
||||
security: [{ basicAuth: [] }],
|
||||
},
|
||||
})
|
||||
.use(apiKeyAuth)
|
||||
.get('/test-key', async ({ body }) => {
|
||||
return body
|
||||
}, {
|
||||
verifyKey: true,
|
||||
detail: {
|
||||
security: [{ basicAuth: [] }],
|
||||
},
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user