fix(auth): legacy signin password bug

This commit is contained in:
Aminejvm 2021-06-09 19:04:01 +01:00
parent 7ec07655dc
commit 5b1380884f
2 changed files with 6 additions and 9 deletions

View File

@ -87,5 +87,5 @@ export default async (req, res) => {
const token = JWT.sign({ id: user.id, username: user.username }, Environment.JWT_SECRET); const token = JWT.sign({ id: user.id, username: user.username }, Environment.JWT_SECRET);
res.status(200).send({ decorator: "SERVER_SIGN_IN", success: true, token }); return res.status(200).send({ decorator: "SERVER_SIGN_IN", success: true, token });
}; };

View File

@ -61,21 +61,18 @@ export const useSignin = ({ onAuthenticate }) => {
if (Events.hasError(response)) return; if (Events.hasError(response)) return;
// NOTE(amine): handling client hash if the user is v2 // NOTE(amine): handling client hash if the user is v2
let hashedPassword; let hashedPassword = await Utilities.encryptPasswordClient(password);
if (response?.data?.version === 1) {
hashedPassword = password; credentialsRef.current = { username, password: hashedPassword };
} else {
hashedPassword = await Utilities.encryptPasswordClient(password);
}
//NOTE(amine): the onAuthenticate function will return early //NOTE(amine): the onAuthenticate function will return early
// if there is shouldMigrate in the response payload // if there is shouldMigrate in the response payload
const passwordSentToServer = response?.data?.version === 1 ? password : hashedPassword;
const authResponse = await onAuthenticate({ const authResponse = await onAuthenticate({
username: username.toLowerCase(), username: username.toLowerCase(),
password: hashedPassword, password: passwordSentToServer,
}); });
credentialsRef.current = { username, password: hashedPassword };
if (authResponse.shouldMigrate) return authResponse; if (authResponse.shouldMigrate) return authResponse;
}; };