Skip to content

Commit 6777ca1

Browse files
fix middlewares
1 parent ff5c575 commit 6777ca1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

apps/backend/src/shared/infra/http/middlewares/authenticate-vendor.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ async function authenticateWithApiKey(
1515
res: MedusaResponse,
1616
next: NextFunction
1717
) {
18+
const service = req.scope.resolve<SellerModuleService>(SELLER_MODULE)
1819
const token = req.headers.authorization?.split(' ')[1] || ''
1920

20-
const service = req.scope.resolve<SellerModuleService>(SELLER_MODULE)
21+
let normalizedToken = token
22+
if (!token.startsWith('ssk_')) {
23+
normalizedToken = Buffer.from(token, 'base64').toString('utf-8')
24+
}
25+
26+
if (normalizedToken.endsWith(':')) {
27+
normalizedToken = normalizedToken.slice(0, -1)
28+
}
2129

2230
const [api_key] = await service.listSellerApiKeys({
23-
token: service.calculateHash(token)
31+
token: service.calculateHash(normalizedToken)
2432
})
2533

2634
if (!api_key || api_key.revoked_at !== null || api_key.deleted_at !== null) {

apps/backend/src/shared/infra/http/utils/seller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const fetchSellerByAuthContext = async (
3838
return fetchSellerByAuthActorId(ctx.actor_id, scope, fields)
3939
}
4040

41-
if (ctx.actor_type === 'seller_api_key') {
41+
if (ctx.actor_type === 'seller-api-key') {
4242
const {
4343
data: [api_key]
4444
} = await query.graph({

0 commit comments

Comments
 (0)