Skip to content

Commit 22a5972

Browse files
committed
switch to backend env for passwords
1 parent 089a506 commit 22a5972

File tree

1 file changed

+13
-10
lines changed
  • backend/services/implementation

1 file changed

+13
-10
lines changed

backend/services/implementation/auth.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ class AuthService implements IAuthService {
1313
role: string,
1414
encryptedPassword: string,
1515
): Promise<{ type: string; accessToken: string }> {
16-
const storedPasswordHash = "abc123";
17-
16+
let storedPasswordHash = "";
1817
// Decrypt the password
1918
// const bytes = CryptoJS.AES.decrypt(encryptedPassword, 'secret-key');
2019
// const password = bytes.toString(CryptoJS.enc.Utf8);
2120

22-
// if (role === "admin_staff") {
23-
// storedPasswordHash = process.env.ADMIN_STAFF_PASSWORD_HASH;
24-
// } else if (role === "release_staff") {
25-
// storedPasswordHash = process.env.RELEASE_STAFF_PASSWORD_HASH;
26-
// } else {
27-
// throw new AuthenticationError("Invalid role");
28-
// }
21+
if (role === "admin_staff") {
22+
storedPasswordHash = process.env.ADMIN_STAFF_PASSWORD_HASH ?? "";
23+
} else if (role === "release_staff") {
24+
storedPasswordHash = process.env.RELEASE_STAFF_PASSWORD_HASH ?? "";
25+
} else {
26+
throw new AuthenticationError("Invalid role");
27+
}
2928

3029
// const isPasswordValid = await bcrypt.compare(
3130
// encryptedPassword,
@@ -38,7 +37,11 @@ class AuthService implements IAuthService {
3837
throw new AuthenticationError("Invalid password");
3938
}
4039

41-
const jwtSecretKey = process.env.JWT_SECRET;
40+
const jwtSecretKey = process.env.JWT_SECRET ?? "";
41+
42+
if (!jwtSecretKey) {
43+
throw new Error("JWT_SECRET is not defined");
44+
}
4245

4346
const token = jwt.sign(
4447
{ role, password: storedPasswordHash },

0 commit comments

Comments
 (0)