Closed Meriem-BM closed 3 days ago
The changes to the fetchAdminAndValidatePassword
function in userService.ts
involve adding early exit logic if the user's encryptedPassword
is null, ensuring the system doesn't attempt to validate a password when it doesn't exist. Error logging within a try-catch
block has also been incorporated to provide better debugging information in case of failures.
File | Change Summary |
---|---|
src/services/userService.ts |
Added a null check for user?.encryptedPassword and implemented error logging within a try-catch block |
In code, where bytes and bits reside,
A password check now we provide,
If none in store, we skip the test,
And error logs help with the rest.
A safer path, a clearer sight,
Our code enhanced, a coder's delight. 🎉
src/services/userService.ts (2)
`78-79`: **Prevent further execution if `encryptedPassword` is `null`.** The added check ensures that the function returns early if `user?.encryptedPassword` is `null`, preventing potential crashes. --- `81-88`: **Handle potential exceptions during password comparison.** The `try-catch` block with error logging is a good addition to handle any exceptions that may occur during the password comparison.
Here is how to reproduce the bug
Connect to admin panel using a user record that has
encryptedPassword = null AND role != 'restricted'
In that case the app crashes showing this page
Summary by CodeRabbit
encryptedPassword
is checked before comparison, preventing potential errors.