Failed to test signature verification
This commit is contained in:
@@ -18,13 +18,11 @@ BEGIN
|
|||||||
DO UPDATE SET last_value = weekly_id_counters.last_value + 1
|
DO UPDATE SET last_value = weekly_id_counters.last_value + 1
|
||||||
RETURNING last_value INTO v_seq;
|
RETURNING last_value INTO v_seq;
|
||||||
|
|
||||||
RETURN format(
|
RETURN
|
||||||
'%s-%02s%02s%04s',
|
p_prefix || '-' ||
|
||||||
p_prefix,
|
to_char((v_yy % 100), 'FM00') ||
|
||||||
v_yy % 100,
|
to_char(v_ww, 'FM00') ||
|
||||||
v_ww,
|
to_char(v_seq, 'FM0000');
|
||||||
v_seq
|
|
||||||
);
|
|
||||||
END;
|
END;
|
||||||
$$;
|
$$;
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import merchantNonces from '~/db/schema/merchant_nonces'
|
|||||||
import { verify } from '~/helpers/signature'
|
import { verify } from '~/helpers/signature'
|
||||||
import { UnauthenticatedError } from '~/helpers/errors'
|
import { UnauthenticatedError } from '~/helpers/errors'
|
||||||
|
|
||||||
export const apiKey = new Elysia().macro({
|
export const apiKeyAuth = new Elysia().macro({
|
||||||
verifyKey: {
|
verifyKey: {
|
||||||
headers: t.Object({
|
headers: t.Object({
|
||||||
'x-api-key': t.String(),
|
'x-api-key': t.String(),
|
||||||
@@ -14,7 +14,7 @@ export const apiKey = new Elysia().macro({
|
|||||||
'x-signature': t.String(),
|
'x-signature': t.String(),
|
||||||
'x-timestamp': t.Number(),
|
'x-timestamp': t.Number(),
|
||||||
}),
|
}),
|
||||||
|
body: t.Unknown(),
|
||||||
async beforeHandle({ headers, body }) {
|
async beforeHandle({ headers, body }) {
|
||||||
const apiKey = headers['x-api-key']
|
const apiKey = headers['x-api-key']
|
||||||
const nonce = headers['x-nonce']
|
const nonce = headers['x-nonce']
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export async function createMerchant(body: CreateMerchantBody) {
|
|||||||
const apiKey = generateApiKey()
|
const apiKey = generateApiKey()
|
||||||
const secretKey = generateSecretKey()
|
const secretKey = generateSecretKey()
|
||||||
|
|
||||||
|
try {
|
||||||
// Insert new merchant
|
// Insert new merchant
|
||||||
const result = await db
|
const result = await db
|
||||||
.insert(table.merchants)
|
.insert(table.merchants)
|
||||||
@@ -37,4 +38,8 @@ export async function createMerchant(body: CreateMerchantBody) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result[0]
|
return result[0]
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error creating merchant:', error)
|
||||||
|
throw new Error('Failed to create merchant')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createMerchantBody, createMerchantResponseSchema } from './schema'
|
|||||||
import CreateMerchantService from './commands/service'
|
import CreateMerchantService from './commands/service'
|
||||||
import { basicAuthMiddleware } from '~/middlewares/basicAuth'
|
import { basicAuthMiddleware } from '~/middlewares/basicAuth'
|
||||||
import { DataAlreadyExistsError } from '~/helpers/errors'
|
import { DataAlreadyExistsError } from '~/helpers/errors'
|
||||||
|
import { apiKeyAuth } from '~/middlewares/apiKeyAuth'
|
||||||
|
|
||||||
export const router = new Elysia({
|
export const router = new Elysia({
|
||||||
name: 'modules.auth',
|
name: 'modules.auth',
|
||||||
@@ -40,5 +41,14 @@ export const router = new Elysia({
|
|||||||
security: [{ basicAuth: [] }],
|
security: [{ basicAuth: [] }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.use(apiKeyAuth)
|
||||||
|
.get('/test-key', async ({ body }) => {
|
||||||
|
return body
|
||||||
|
}, {
|
||||||
|
verifyKey: true,
|
||||||
|
detail: {
|
||||||
|
security: [{ basicAuth: [] }],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|||||||
Reference in New Issue
Block a user