93
apps/console/src/__generated__/iam/ResetPasswordPageMutation.graphql.ts
generated
Normal file
93
apps/console/src/__generated__/iam/ResetPasswordPageMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<7f9521bd0d19cc1410fcb66ddc75fbf2>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
export type ResetPasswordInput = {
|
||||||
|
password: string;
|
||||||
|
token: string;
|
||||||
|
};
|
||||||
|
export type ResetPasswordPageMutation$variables = {
|
||||||
|
input: ResetPasswordInput;
|
||||||
|
};
|
||||||
|
export type ResetPasswordPageMutation$data = {
|
||||||
|
readonly resetPassword: {
|
||||||
|
readonly success: boolean;
|
||||||
|
} | null | undefined;
|
||||||
|
};
|
||||||
|
export type ResetPasswordPageMutation = {
|
||||||
|
response: ResetPasswordPageMutation$data;
|
||||||
|
variables: ResetPasswordPageMutation$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = [
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "input"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v1 = [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "input",
|
||||||
|
"variableName": "input"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"concreteType": "ResetPasswordPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "resetPassword",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "success",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "ResetPasswordPageMutation",
|
||||||
|
"selections": (v1/*: any*/),
|
||||||
|
"type": "Mutation",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "ResetPasswordPageMutation",
|
||||||
|
"selections": (v1/*: any*/)
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "e83c05ebe7c286a362ab11d60182ab61",
|
||||||
|
"id": null,
|
||||||
|
"metadata": {},
|
||||||
|
"name": "ResetPasswordPageMutation",
|
||||||
|
"operationKind": "mutation",
|
||||||
|
"text": "mutation ResetPasswordPageMutation(\n $input: ResetPasswordInput!\n) {\n resetPassword(input: $input) {\n success\n }\n}\n"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "dc17c5c4103a29d3f163d08877bfbb34";
|
||||||
|
|
||||||
|
export default node;
|
||||||
@@ -1,9 +1,20 @@
|
|||||||
import { Link, useNavigate } from "react-router";
|
|
||||||
import { Button, Field, useToast } from "@probo/ui";
|
|
||||||
import { useTranslate } from "@probo/i18n";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
|
||||||
import { usePageTitle } from "@probo/hooks";
|
import { usePageTitle } from "@probo/hooks";
|
||||||
|
import { useTranslate } from "@probo/i18n";
|
||||||
|
import { Button, Field, useToast } from "@probo/ui";
|
||||||
|
import { Link, useNavigate, useSearchParams } from "react-router";
|
||||||
|
import z from "zod";
|
||||||
|
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||||
|
import { graphql } from "relay-runtime";
|
||||||
|
import { useMutation } from "react-relay";
|
||||||
|
import type { ResetPasswordPageMutation } from "/__generated__/iam/ResetPasswordPageMutation.graphql";
|
||||||
|
|
||||||
|
const resetPasswordMutation = graphql`
|
||||||
|
mutation ResetPasswordPageMutation($input: ResetPasswordInput!) {
|
||||||
|
resetPassword(input: $input) {
|
||||||
|
success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
const schema = z
|
const schema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -17,8 +28,13 @@ const schema = z
|
|||||||
|
|
||||||
export default function ResetPasswordPage() {
|
export default function ResetPasswordPage() {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const navigate = useNavigate();
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const token = searchParams.get("token");
|
||||||
|
|
||||||
|
usePageTitle(__("Reset password"));
|
||||||
|
|
||||||
const { register, handleSubmit, formState } = useFormWithSchema(schema, {
|
const { register, handleSubmit, formState } = useFormWithSchema(schema, {
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
password: "",
|
password: "",
|
||||||
@@ -26,10 +42,11 @@ export default function ResetPasswordPage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (data) => {
|
const [resetPassword] = useMutation<ResetPasswordPageMutation>(
|
||||||
const searchParams = new URLSearchParams(location.search);
|
resetPasswordMutation,
|
||||||
const token = searchParams.get("token");
|
);
|
||||||
|
|
||||||
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
toast({
|
toast({
|
||||||
title: __("Reset failed"),
|
title: __("Reset failed"),
|
||||||
@@ -39,38 +56,30 @@ export default function ResetPasswordPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch("/connect/reset-password", {
|
resetPassword({
|
||||||
method: "POST",
|
variables: {
|
||||||
headers: {
|
input: {
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
credentials: "include",
|
|
||||||
body: JSON.stringify({
|
|
||||||
token: token,
|
|
||||||
password: data.password,
|
password: data.password,
|
||||||
}),
|
token,
|
||||||
});
|
},
|
||||||
|
},
|
||||||
// Reset failed
|
onError: (e: Error) => {
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}));
|
|
||||||
toast({
|
toast({
|
||||||
title: __("Reset failed"),
|
title: __("Reset failed"),
|
||||||
description: errorData.message || __("Password reset failed"),
|
description: e.message || __("Password reset failed"),
|
||||||
variant: "error",
|
variant: "error",
|
||||||
});
|
});
|
||||||
return;
|
},
|
||||||
}
|
onCompleted: () => {
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: __("Success"),
|
title: __("Success"),
|
||||||
description: __("Password reset successfully"),
|
description: __("Password reset successfully"),
|
||||||
variant: "success",
|
variant: "success",
|
||||||
});
|
});
|
||||||
navigate("/auth/login", { replace: true });
|
navigate("/auth/login", { replace: true });
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
usePageTitle(__("Reset password"));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 w-full max-w-md mx-auto">
|
<div className="space-y-6 w-full max-w-md mx-auto">
|
||||||
@@ -5,6 +5,7 @@ import { useMutation } from "react-relay";
|
|||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
import { graphql } from "relay-runtime";
|
import { graphql } from "relay-runtime";
|
||||||
import type { PasswordSignInPageMutation } from "/__generated__/iam/PasswordSignInPageMutation.graphql";
|
import type { PasswordSignInPageMutation } from "/__generated__/iam/PasswordSignInPageMutation.graphql";
|
||||||
|
import { formatError, type GraphQLError } from "@probo/helpers";
|
||||||
|
|
||||||
const signInMutation = graphql`
|
const signInMutation = graphql`
|
||||||
mutation PasswordSignInPageMutation($input: SignInInput!) {
|
mutation PasswordSignInPageMutation($input: SignInInput!) {
|
||||||
@@ -39,13 +40,25 @@ export default function PasswordSignInPage() {
|
|||||||
password: passwordValue,
|
password: passwordValue,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onCompleted: () => {
|
onCompleted: (_, error) => {
|
||||||
|
if (error) {
|
||||||
|
toast({
|
||||||
|
title: __("Error"),
|
||||||
|
description: formatError(
|
||||||
|
__("Failed to login"),
|
||||||
|
error as GraphQLError,
|
||||||
|
),
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
},
|
},
|
||||||
onError: (e) => {
|
onError: (e) => {
|
||||||
toast({
|
toast({
|
||||||
title: __("Error"),
|
title: __("Error"),
|
||||||
description: e instanceof Error ? e.message : __("Failed to login"),
|
description: e.message,
|
||||||
variant: "error",
|
variant: "error",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ const routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "register",
|
path: "register",
|
||||||
Component: lazy(() => import("./pages/iam/auth/SignUpPage")),
|
Component: lazy(() => import("./pages/iam/auth/sign-up/SignUpPage")),
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// path: "confirm-email",
|
// path: "confirm-email",
|
||||||
@@ -88,7 +88,7 @@ const routes = [
|
|||||||
{
|
{
|
||||||
path: "signup-from-invitation",
|
path: "signup-from-invitation",
|
||||||
Component: lazy(
|
Component: lazy(
|
||||||
() => import("./pages/iam/auth/SignUpFromInvitationPage"),
|
() => import("./pages/iam/auth/sign-up/SignUpFromInvitationPage"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -97,7 +97,7 @@ const routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "reset-password",
|
path: "reset-password",
|
||||||
Component: lazy(() => import("./pages/auth/ResetPasswordPage")),
|
Component: lazy(() => import("./pages/iam/auth/ResetPasswordPage")),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ func (s AuthService) OpenSessionWithPassword(ctx context.Context, email mail.Add
|
|||||||
|
|
||||||
err := v.Error()
|
err := v.Error()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, NewInvalidPasswordError("invalid password")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -358,8 +358,13 @@ func (r *mutationResolver) SignIn(ctx context.Context, input types.SignInInput)
|
|||||||
|
|
||||||
user, session, err := r.iam.AuthService.OpenSessionWithPassword(ctx, input.Email, input.Password)
|
user, session, err := r.iam.AuthService.OpenSessionWithPassword(ctx, input.Email, input.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var ErrInvalidCredentials *iam.ErrInvalidCredentials
|
var errInvalidPassword *iam.ErrInvalidPassword
|
||||||
if errors.As(err, &ErrInvalidCredentials) {
|
if errors.As(err, &errInvalidPassword) {
|
||||||
|
return nil, graphql.ErrorOnPath(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var errInvalidCredentials *iam.ErrInvalidCredentials
|
||||||
|
if errors.As(err, &errInvalidCredentials) {
|
||||||
return nil, &gqlerror.Error{
|
return nil, &gqlerror.Error{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
Extensions: map[string]any{
|
Extensions: map[string]any{
|
||||||
|
|||||||
Reference in New Issue
Block a user