Skip to content

Commit d0f6ac1

Browse files
authored
refactor: create some constants to avoid hardcoded values (#2)
2 parents 023764f + 5317aac commit d0f6ac1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
const jwt = require("jsonwebtoken");
22

3-
// Constants.
3+
// JWT constants.
44
const JWT_PUBLIC_KEY = process.env.JWT_PUBLIC_KEY;
5+
const JWT_RS256_ALGORITHM = "RS256";
6+
7+
// General constants.
8+
const STRING_TYPE = "string";
59

610
exports.handler = async (event) => {
711
// Gets event header.
812
const header =
9-
typeof event.header === "string" ? JSON.parse(event.header) : event.header;
13+
typeof event.header === STRING_TYPE
14+
? JSON.parse(event.header)
15+
: event.header;
1016

1117
// Needs to be authorized by a given token.
1218
const token = header.token;
@@ -15,7 +21,7 @@ exports.handler = async (event) => {
1521
const jwtSettings = {
1622
publicKey: JWT_PUBLIC_KEY,
1723
options: {
18-
algorithms: ["RS256"],
24+
algorithms: [JWT_RS256_ALGORITHM],
1925
},
2026
};
2127

0 commit comments

Comments
 (0)