Skip to content

Commit

Permalink
refactor: use uid to create the refreshToken
Browse files Browse the repository at this point in the history
  • Loading branch information
Williancc1557 committed Aug 9, 2022
1 parent f950378 commit 6e0ac13
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"pino": "^8.3.0",
"pino-http": "^8.1.1",
"pino-pretty": "^8.1.0",
"uuidv4": "^6.2.13",
"uid": "^2.0.0",
"validator": "^13.7.0"
}
}
6 changes: 2 additions & 4 deletions src/utils/create-refresh-token/create-refresh-token.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import jwt from "jsonwebtoken";
import { UtilCreateRefreshToken } from "./create-refresh-token";

describe("CreateRefreshToken", () => {
test("should return refreshToken if sucess", () => {
test("should return refreshToken if success", () => {
const sut = new UtilCreateRefreshToken();
jest.spyOn(jwt, "sign");

const res = sut.create("user_id");
const res = sut.create();

expect(res).toBeTruthy();
});
Expand Down
17 changes: 6 additions & 11 deletions src/utils/create-refresh-token/create-refresh-token.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import jwt from "jsonwebtoken";
import env from "../../main/config/env";
import { uid } from "uid";
import type { CreateRefreshToken } from "../../data/protocols";

export class UtilCreateRefreshToken {
public create(userId: string): string {
return jwt.sign(
{
aud: userId,
sub: "user",
},
env.secretRefreshTokenJwt
);
export class UtilCreateRefreshToken implements CreateRefreshToken {
public create(): string {
const LENGTH = 25;
return uid(LENGTH);
}
}
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,11 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@lukeed/csprng@^1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@lukeed/csprng/-/csprng-1.0.1.tgz#625e93a0edb2c830e3c52ce2d67b9d53377c6a66"
integrity sha512-uSvJdwQU5nK+Vdf6zxcWAY2A8r7uqe+gePwLWzJ+fsQehq18pc0I2hJKwypZ2aLM90+Er9u1xn4iLJPZ+xlL4g==

"@mapbox/node-pre-gyp@^1.0.0":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.9.tgz#09a8781a3a036151cdebbe8719d6f8b25d4058bc"
Expand Down Expand Up @@ -5217,6 +5222,13 @@ typescript@^4.7.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

uid@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/uid/-/uid-2.0.0.tgz#1773bec106e96955f1658f20272e2ccea414e8bc"
integrity sha512-hFw+zKBA1szYdbZWj6FjTxZzJnKNf+wTDcsxlJaXS64MCy9LQEmJUVieGYHCKek/WRyFIcs0cEXtGIQmfvHe2A==
dependencies:
"@lukeed/csprng" "^1.0.0"

unbox-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"
Expand Down Expand Up @@ -5267,7 +5279,7 @@ [email protected], uuid@^8.3.1:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuidv4@*, uuidv4@^6.2.13:
uuidv4@*:
version "6.2.13"
resolved "https://registry.yarnpkg.com/uuidv4/-/uuidv4-6.2.13.tgz#8f95ec5ef22d1f92c8e5d4c70b735d1c89572cb7"
integrity sha512-AXyzMjazYB3ovL3q051VLH06Ixj//Knx7QnUSi1T//Ie3io6CpsPu9nVMOx5MoLWh6xV0B9J0hIaxungxXUbPQ==
Expand Down

0 comments on commit 6e0ac13

Please sign in to comment.