Skip to content

Commit

Permalink
fix(com-api): user new crypto pre configs and new env names
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD authored and njfamirm committed May 18, 2023
1 parent e4d1a55 commit 244b418
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 13 additions & 6 deletions uniquely/com-api/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import {TokenGeneratorConfig} from '@alwatr/crypto';
import {createLogger} from '@alwatr/logger';

export const logger = createLogger('com-api');

if (process.env.NODE_ENV === 'production') {
if (process.env.STORAGE_TOKEN == null) {
throw new Error('STORAGE_TOKEN is required in production');
}

if (process.env.TOKEN_GENERATOR_SECRET == null) {
throw new Error('TOKEN_GENERATOR_SECRET is required in production');
}
}

export const config = {
storageClient: {
host: process.env.STORAGE_HOST ?? '127.0.0.1',
port: process.env.STORAGE_PORT != null ? +process.env.STORAGE_PORT : 9000,
token: process.env.STORAGE_TOKEN ?? 'YOUR_SECRET_TOKEN',
token: process.env.STORAGE_TOKEN ?? 'YOUR_SECRET',
},

token: <TokenGeneratorConfig>{
secret: process.env.SECRET ?? 'YOUR_SECRET',
algorithm: 'sha224',
encoding: 'base64url',
token: {
secret: process.env.TOKEN_GENERATOR_SECRET ?? 'YOUR_SECRET',
duration: '6M',
},

Expand Down
10 changes: 8 additions & 2 deletions uniquely/com-api/src/lib/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {AlwatrUserFactory} from '@alwatr/crypto';
import {AlwatrUserFactory, userIdGeneratorPreConfig, userTokenGeneratorPreConfig} from '@alwatr/crypto';

import {config} from './config.js';

export const userFactory = new AlwatrUserFactory(config.token);
export const userFactory = new AlwatrUserFactory(
userIdGeneratorPreConfig,
{
...userTokenGeneratorPreConfig,
...config.token,
},
);

0 comments on commit 244b418

Please sign in to comment.