Skip to content

Commit

Permalink
feat: return jwt credential without store encrypted data
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhyen99 committed Sep 13, 2024
1 parent 9eec9ff commit fc3bc8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@
},
"engines": {
"node": "20.12.2"
},
"dependencies": {
"debug": "^4.3.7"
}
}
28 changes: 18 additions & 10 deletions packages/encrypted-storage/src/encrypted-store-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { IAgent, IEncrypteAndStoreDataResult } from '@vckit/core-types';
import { NextFunction, Request, Response, Router } from 'express';
import interceptor from 'express-interceptor';
import { RequestWithAgent } from './encrypted-store-router.js';
import Debug from 'debug';

const debug = Debug('vckit:encrypted-storage');

/**
*
Expand All @@ -14,7 +17,7 @@ export function encryptedStoreMiddleware(args: {

const intercept = interceptor(function (
req: RequestWithAgent,
res: Response
res: Response,
) {
return {
isInterceptable: function () {
Expand All @@ -32,7 +35,7 @@ export function encryptedStoreMiddleware(args: {
) {
updatedBody = await encryptAndStoreData(
req.agent,
JSON.parse(body)
JSON.parse(body),
);
}

Expand All @@ -50,12 +53,17 @@ export function encryptedStoreMiddleware(args: {
}

async function encryptAndStoreData(agent: IAgent, payload: object) {
const { id, key }: IEncrypteAndStoreDataResult = await agent.execute(
'encryptAndStoreData',
{
data: payload,
}
);

return JSON.stringify({ id, key, credential: payload });
try {
const { id, key }: IEncrypteAndStoreDataResult = await agent.execute(
'encryptAndStoreData',
{
data: payload,
},
);

return JSON.stringify({ id, key, credential: payload });
} catch (error) {
debug(error);
return JSON.stringify({ credential: payload });
}
}

0 comments on commit fc3bc8f

Please sign in to comment.