mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 23:47:12 +00:00
fix(user): populate correct error message on client (#9043)
* fix(user): populate correct error message on client * fix(user): populate correct error message on client
This commit is contained in:
parent
144e866afc
commit
6709b09646
@ -2,7 +2,7 @@ import axios from 'api';
|
|||||||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { ErrorResponse, SuccessResponse } from 'types/api';
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||||
import { PayloadProps, Props } from 'types/api/user/loginPrecheck';
|
import { Props, Signup as PayloadProps } from 'types/api/user/loginPrecheck';
|
||||||
|
|
||||||
const loginPrecheck = async (
|
const loginPrecheck = async (
|
||||||
props: Props,
|
props: Props,
|
||||||
|
|||||||
@ -1,25 +1,21 @@
|
|||||||
import axios from 'api';
|
import axios from 'api';
|
||||||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { ErrorResponse, SuccessResponse } from 'types/api';
|
import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
|
||||||
import { PayloadProps } from 'types/api/user/loginPrecheck';
|
import { PayloadProps, Signup } from 'types/api/user/loginPrecheck';
|
||||||
import { Props } from 'types/api/user/signup';
|
import { Props } from 'types/api/user/signup';
|
||||||
|
|
||||||
const signup = async (
|
const signup = async (props: Props): Promise<SuccessResponseV2<Signup>> => {
|
||||||
props: Props,
|
|
||||||
): Promise<SuccessResponse<null | PayloadProps> | ErrorResponse> => {
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`/register`, {
|
const response = await axios.post<PayloadProps>(`/register`, {
|
||||||
...props,
|
...props,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
statusCode: 200,
|
httpStatusCode: response.status,
|
||||||
error: null,
|
data: response.data.data,
|
||||||
message: response.data.status,
|
|
||||||
payload: response.data?.data,
|
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return ErrorResponseHandler(error as AxiosError);
|
ErrorResponseHandlerV2(error as AxiosError<ErrorV2Resp>);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import { useAppContext } from 'providers/App/App';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import APIError from 'types/api/error';
|
import APIError from 'types/api/error';
|
||||||
import { PayloadProps as PrecheckResultType } from 'types/api/user/loginPrecheck';
|
import { Signup as PrecheckResultType } from 'types/api/user/loginPrecheck';
|
||||||
|
|
||||||
import { FormContainer, Label, ParentContainer } from './styles';
|
import { FormContainer, Label, ParentContainer } from './styles';
|
||||||
|
|
||||||
|
|||||||
@ -10,13 +10,14 @@ import afterLogin from 'AppRoutes/utils';
|
|||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import { useNotifications } from 'hooks/useNotifications';
|
import { useNotifications } from 'hooks/useNotifications';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
|
import { useErrorModal } from 'providers/ErrorModalProvider';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { SuccessResponseV2 } from 'types/api';
|
import { SuccessResponseV2 } from 'types/api';
|
||||||
import APIError from 'types/api/error';
|
import APIError from 'types/api/error';
|
||||||
import { InviteDetails } from 'types/api/user/getInviteDetails';
|
import { InviteDetails } from 'types/api/user/getInviteDetails';
|
||||||
import { PayloadProps as LoginPrecheckPayloadProps } from 'types/api/user/loginPrecheck';
|
import { Signup as LoginPrecheckPayloadProps } from 'types/api/user/loginPrecheck';
|
||||||
|
|
||||||
import { FormContainer, Label } from './styles';
|
import { FormContainer, Label } from './styles';
|
||||||
import { isPasswordNotValidMessage, isPasswordValid } from './utils';
|
import { isPasswordNotValidMessage, isPasswordValid } from './utils';
|
||||||
@ -109,31 +110,27 @@ function SignUp(): JSX.Element {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const isSignUp = token === null;
|
const isSignUp = token === null;
|
||||||
|
const { showErrorModal } = useErrorModal();
|
||||||
|
|
||||||
const signUp = async (values: FormValues): Promise<void> => {
|
const signUp = async (values: FormValues): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organizationName, password, email } = values;
|
const { organizationName, password, email } = values;
|
||||||
const response = await signUpApi({
|
await signUpApi({
|
||||||
email,
|
email,
|
||||||
orgDisplayName: organizationName,
|
orgDisplayName: organizationName,
|
||||||
password,
|
password,
|
||||||
token: params.get('token') || undefined,
|
token: params.get('token') || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.statusCode === 200) {
|
const loginResponse = await loginApi({
|
||||||
const loginResponse = await loginApi({
|
email,
|
||||||
email,
|
password,
|
||||||
password,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data } = loginResponse;
|
|
||||||
await afterLogin(data.userId, data.accessJwt, data.refreshJwt);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
notifications.error({
|
|
||||||
message: (error as APIError).getErrorCode(),
|
|
||||||
description: (error as APIError).getErrorMessage(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { data } = loginResponse;
|
||||||
|
await afterLogin(data.userId, data.accessJwt, data.refreshJwt);
|
||||||
|
} catch (error) {
|
||||||
|
showErrorModal(error as APIError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { User } from 'types/reducer/app';
|
|||||||
import { ROLES } from 'types/roles';
|
import { ROLES } from 'types/roles';
|
||||||
|
|
||||||
import { Organization } from './getOrganization';
|
import { Organization } from './getOrganization';
|
||||||
import { PayloadProps as LoginPrecheckPayloadProps } from './loginPrecheck';
|
import { Signup as LoginPrecheckPayloadProps } from './loginPrecheck';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
inviteId: string;
|
inviteId: string;
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
export interface PayloadProps {
|
export interface PayloadProps {
|
||||||
|
data: Signup;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Signup {
|
||||||
sso: boolean;
|
sso: boolean;
|
||||||
ssoUrl?: string;
|
ssoUrl?: string;
|
||||||
canSelfRegister?: boolean;
|
canSelfRegister?: boolean;
|
||||||
|
|||||||
@ -2061,7 +2061,7 @@ func (aH *APIHandler) registerUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var req types.PostableRegisterOrgAndAdmin
|
var req types.PostableRegisterOrgAndAdmin
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorBadData}, nil)
|
render.Error(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user