Skip to content

Commit

Permalink
refactor devedency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
adeiskandarzulkarnaen committed Dec 6, 2024
1 parent 93862ff commit 621cad4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/bunhono_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ jobs:
bun run lint
bun run test
env:
APP_PORT: 3000
APP_PORT: ${{ variables.APP_PORT }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
ACCESS_TOKEN_AGE: ${{ variables.ACCESS_TOKEN_AGE }}
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
15 changes: 0 additions & 15 deletions src/Infrastructures/container.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* istanbul ignore file */

import { createContainer } from 'instances-container';

// external agency
import { password } from 'bun';
import { sign, verify } from 'hono/jwt';
import prismaClient from '@infrastructures/database/prismaClient';


Expand Down Expand Up @@ -44,22 +41,10 @@ container.register([
{
key: PasswordHash.name,
Class: BunBCryptPasswordHash,
parameter: {
injectType: 'parameter',
dependencies: [
{ concrete: password }
]
}
},
{
key: AuthenticationTokenManager.name,
Class: HonoJwtTokenManager,
parameter: {
injectType: 'parameter',
dependencies: [
{ concrete: { sign, verify } }
]
}
}
]);

Expand Down
6 changes: 3 additions & 3 deletions src/Infrastructures/security/BunBCryptPasswordHash.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { password } from 'bun';
import { password } from 'bun';
import AuthenticationError from '@commons/exceptions/AuthenticationError';
import PasswordHash from '@applications/security/PasswordHash';


class BunBCryptPasswordHash extends PasswordHash {
private readonly password;
private readonly saltRound;
constructor(bunpassword: typeof password, saltRound: number = 10) {
constructor(saltRound: number = 10) {
super();
this.password = bunpassword;
this.password = password;
this.saltRound = saltRound;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Infrastructures/security/HonoJwtTokenManager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { sign, verify } from 'hono/jwt';
import type { JWTPayload } from 'hono/utils/jwt/types';
import { sign, verify } from 'hono/jwt';
import { JWTPayload } from 'hono/utils/jwt/types';
import AuthenticationTokenManager from '@applications/security/AuthenticationTokenManager';
import InvariantError from '@commons/exceptions/InvariantError';



class HonoJwtTokenManager extends AuthenticationTokenManager {
constructor(public readonly honoJwt: { sign: typeof sign, verify: typeof verify }) {
public readonly honoJwt;
constructor() {
super();
this.honoJwt = { sign, verify };
}

public async generateAccessToken(payload: object): Promise<string> {
Expand Down

0 comments on commit 621cad4

Please sign in to comment.