Skip to content

Commit

Permalink
feat(cop-api): requireToken
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and AliMD committed Feb 11, 2023
1 parent e4dbe33 commit d1e3c61
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 4 additions & 2 deletions uniquely/com-api/demo.http
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ GET {{apiUrl}}/

### Get all product
Get {{apiUrl}}/product/
Authorization: Bearer {{token}}

### New order of user
PUT {{apiUrl}}/order/?userId=abc123
Authorization: Bearer {{userToken}}
Authorization: Bearer {{token}}
Content-Type: application/json
client-id: 2b6861f4-a8d7-4065-a5a5-3caa54b71a20

{
"itemList": [
Expand Down Expand Up @@ -42,4 +44,4 @@ Content-Type: application/json

### Get all orders list of special user
get {{apiUrl}}/order/?userId=abc123
Authorization: Bearer {{userToken}}
Authorization: Bearer {{token}}
10 changes: 5 additions & 5 deletions uniquely/com-api/src/route/get-order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {logger} from '../lib/config.js';
import {config, logger} from '../lib/config.js';
import {nanoServer} from '../lib/server.js';
import {storageClient} from '../lib/storage.js';
import {tokenGenerator} from '../lib/token.js';

import type {Order} from '@alwatr/type/customer-order-management.js';

Expand All @@ -10,9 +9,10 @@ nanoServer.route('GET', '/order/', async (connection) => {
logger.logMethod('get-order');

const params = connection.requireQueryParams<{userId: string}>({userId: 'string'});
connection.requireToken((token: string) => {
return tokenGenerator.verify(params.userId, token) === 'valid';
});
// connection.requireToken((token: string) => {
// return tokenGenerator.verify(params.userId, token) === 'valid';
// });
connection.requireToken(config.nanoServer.accessToken);

return await storageClient.getStorage<Order>(params.userId);
});
3 changes: 2 additions & 1 deletion uniquely/com-api/src/route/get-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {storageClient} from '../lib/storage.js';

import type {Product} from '@alwatr/type/src/customer-order-management.js';

nanoServer.route('GET', '/product/', async () => {
nanoServer.route('GET', '/product/', async (connection) => {
logger.logMethod('get-product');
connection.requireToken(config.nanoServer.accessToken);
return await storageClient.getStorage<Product>(config.storage.productStorageName);
});
10 changes: 5 additions & 5 deletions uniquely/com-api/src/route/put-order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {logger} from '../lib/config.js';
import {config, logger} from '../lib/config.js';
import {nanoServer} from '../lib/server.js';
import {storageClient} from '../lib/storage.js';
import {tokenGenerator} from '../lib/token.js';

import type {Order} from '@alwatr/type/customer-order-management.js';

Expand All @@ -10,9 +9,10 @@ nanoServer.route('PUT', '/order/', async (connection) => {
logger.logMethod('put-order');

const params = connection.requireQueryParams<{userId: string}>({userId: 'string'});
connection.requireToken((token: string) => {
return tokenGenerator.verify(params.userId, token) === 'valid';
});
// connection.requireToken((token: string) => {
// return tokenGenerator.verify(params.userId, token) === 'valid';
// });
connection.requireToken(config.nanoServer.accessToken);
const remoteAddress = connection.getRemoteAddress();
const clientId = connection.requireClientId();

Expand Down

0 comments on commit d1e3c61

Please sign in to comment.