Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat(reset-password): use the v2 endpoint on the reset password page (#12492)

Vikrant Gupta0f3fb7106754
diff --git a/frontend/src/api/v1/factor_password/resetPassword.ts b/frontend/src/api/v1/factor_password/resetPassword.ts
deleted file mode 100644
index 97c0b8cbed..0000000000
--- a/frontend/src/api/v1/factor_password/resetPassword.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import axios from 'api';
-import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
-import { AxiosError } from 'axios';
-import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
-import { PayloadProps, Props } from 'types/api/user/resetPassword';
-
-/**
- * @deprecated Use the generated `useResetPassword` hook (or `resetPassword` fetcher) from
- * `api/generated/services/users` instead. This hand-written client targets the
- * same endpoint and will be removed once call sites migrate.
- *
- * Part of https://github.com/SigNoz/engineering-pod/issues/5289, add a comment or update when removing this method.
- */
-const resetPassword = async (
- props: Props,
-): Promise<SuccessResponseV2<PayloadProps>> => {
- try {
- const response = await axios.post<PayloadProps>(`/resetPassword`, {
- ...props,
- });
-
- return {
- httpStatusCode: response.status,
- data: response.data,
- };
- } catch (error) {
- ErrorResponseHandlerV2(error as AxiosError<ErrorV2Resp>);
- }
-};
-
-export default resetPassword;
diff --git a/frontend/src/container/ResetPassword/__tests__/ResetPassword.test.tsx b/frontend/src/container/ResetPassword/__tests__/ResetPassword.test.tsx
index 6c072d6fe6..a8ed31b3a0 100644
--- a/frontend/src/container/ResetPassword/__tests__/ResetPassword.test.tsx
+++ b/frontend/src/container/ResetPassword/__tests__/ResetPassword.test.tsx
@@ -33,7 +33,7 @@ jest.mock('hooks/useNotifications', () => ({
}),
}));
-const RESET_PASSWORD_ENDPOINT = '*/resetPassword';
+const RESET_PASSWORD_ENDPOINT = '*/api/v2/factor_password/reset';
const mockHistoryPush = history.push as jest.MockedFunction<
typeof history.push
diff --git a/frontend/src/container/ResetPassword/index.tsx b/frontend/src/container/ResetPassword/index.tsx
index cdefd21bc4..466d575ac9 100644
--- a/frontend/src/container/ResetPassword/index.tsx
+++ b/frontend/src/container/ResetPassword/index.tsx
@@ -1,11 +1,12 @@
-import { useState } from 'react';
+import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-use';
import { Button } from '@signozhq/ui/button';
import { Callout } from '@signozhq/ui/callout';
import { Form, Input as AntdInput } from 'antd';
import { Typography } from '@signozhq/ui/typography';
-import resetPasswordApi from 'api/v1/factor_password/resetPassword';
+import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';
+import { useResetPassword } from 'api/generated/services/users';
import AuthError from 'components/AuthError/AuthError';
import AuthPageContainer from 'components/AuthPageContainer';
import ROUTES from 'constants/routes';
@@ -14,7 +15,6 @@ import { useNotifications } from 'hooks/useNotifications';
import history from 'lib/history';
import { ArrowRight, CircleAlert, KeyRound } from '@signozhq/icons';
import { Label } from 'pages/SignUp/styles';
-import APIError from 'types/api/error';
import { FormContainer } from './styles';
@@ -26,40 +26,41 @@ function ResetPassword({ version }: ResetPasswordProps): JSX.Element {
const [confirmPasswordError, setConfirmPasswordError] =
useState<boolean>(false);
- const [errorMessage, setErrorMessage] = useState<APIError | null>();
-
const [isValidPassword, setIsValidPassword] = useState(false);
- const [loading, setLoading] = useState(false);
const { t } = useTranslation(['common']);
const { search } = useLocation();
const params = new URLSearchParams(search);
const token = params.get('token');
const { notifications } = useNotifications();
+ const {
+ mutate: resetPassword,
+ isLoading,
+ error: mutationError,
+ } = useResetPassword();
+
+ const errorMessage = useMemo(
+ () => convertToApiError(mutationError),
+ [mutationError],
+ );
+
const [form] = Form.useForm<FormValues>();
- const handleFormSubmit: () => Promise<void> = async () => {
- try {
- setLoading(true);
- setErrorMessage(null);
- const { password } = form.getFieldsValue();
-
- await resetPasswordApi({
- password,
- token: token || '',
- });
-
- notifications.success({
- message: t('success', {
- ns: 'common',
- }),
- });
- history.push(ROUTES.LOGIN);
-
- setLoading(false);
- } catch (error) {
- setLoading(false);
- setErrorMessage(error as APIError);
- }
+ const handleFormSubmit = (): void => {
+ const { password } = form.getFieldsValue();
+
+ resetPassword(
+ { data: { password, token: token || '' } },
+ {
+ onSuccess: (): void => {
+ notifications.success({
+ message: t('success', {
+ ns: 'common',
+ }),
+ });
+ history.push(ROUTES.LOGIN);
+ },
+ },
+ );
};
const validatePassword = (): boolean => {
@@ -222,7 +223,7 @@ function ResetPassword({ version }: ResetPasswordProps): JSX.Element {
color="primary"
type="submit"
data-attr="reset-password"
- disabled={!isValidPassword || loading}
+ disabled={!isValidPassword || isLoading}
className="reset-password-submit-button"
suffix={<ArrowRight size={16} />}
>
diff --git a/frontend/src/types/api/user/resetPassword.ts b/frontend/src/types/api/user/resetPassword.ts
deleted file mode 100644
index fd00e40494..0000000000
--- a/frontend/src/types/api/user/resetPassword.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export interface Props {
- token: string;
- password: string;
-}
-
-export interface PayloadProps {
- data: string;
- status: string;
-}