Skip to content

Commit

Permalink
[fix] fixes check for reusing old password in reset password (#92)
Browse files Browse the repository at this point in the history
* fix: fixes check for reusing old password in reset password

* refactor: renames helper
  • Loading branch information
varortz authored May 24, 2024
1 parent cd5cd20 commit 54af926
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/api/supabase/queries/password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import supabase from '../createClient';
* Checks if the current password is different from the current user's password
* @returns a Promise of whether the password is different
*/
export async function verifyUserPassword(password: string): Promise<boolean> {
export async function verifyNewPassword(password: string): Promise<boolean> {
const { data, error } = await supabase.rpc('verify_user_password', {
password,
});
Expand Down
8 changes: 3 additions & 5 deletions src/app/(auth)/reset-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import supabase from '@/api/supabase/createClient';
import { verifyUserPassword } from '@/api/supabase/queries/password';
import { verifyNewPassword } from '@/api/supabase/queries/password';
import { BigBlueButton } from '@/components/Buttons';
import PasswordComplexity from '@/components/PasswordComplexity';
import TextInput from '@/components/TextInput/index';
Expand Down Expand Up @@ -39,10 +39,8 @@ export default function ResetPassword() {
setErrorMessage('Passwords do not match.');
return;
}
if (!verifyUserPassword(newPassword)) {
setErrorMessage(
'Password cannot be the same as your previous password. Please choose a different password.',
);
if (await verifyNewPassword(newPassword)) {
setErrorMessage('New password must be different from the old password.');
return;
}
setErrorMessage('');
Expand Down

0 comments on commit 54af926

Please sign in to comment.