Redirect when already authenticated
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { GraphQLError } from "@probo/helpers";
|
||||
import { usePageTitle } from "@probo/hooks";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Button, Field, useToast } from "@probo/ui";
|
||||
@@ -11,6 +12,7 @@ import { graphql } from "relay-runtime";
|
||||
import { z } from "zod";
|
||||
|
||||
import { useFormWithSchema } from "#/hooks/useFormWithSchema";
|
||||
import { getPathPrefix } from "#/utils/pathPrefix";
|
||||
|
||||
import type { ConnectPageMutation } from "./__generated__/ConnectPageMutation.graphql";
|
||||
import type { ConnectPageQuery } from "./__generated__/ConnectPageQuery.graphql";
|
||||
@@ -96,8 +98,16 @@ export function ConnectPage(props: {
|
||||
email,
|
||||
},
|
||||
},
|
||||
onCompleted: (_, errors) => {
|
||||
if (errors?.length) {
|
||||
onCompleted: (data, errors: GraphQLError[] | null) => {
|
||||
console.log(data, errors);
|
||||
if (errors) {
|
||||
for (const err of errors) {
|
||||
if (err.extensions?.code === "ALREADY_AUTHENTICATED") {
|
||||
const pathPrefix = getPathPrefix();
|
||||
window.location.href = pathPrefix ? getPathPrefix() : "/";
|
||||
return;
|
||||
}
|
||||
}
|
||||
toast({
|
||||
title: __("Error"),
|
||||
description: __("Cannot send magic link"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { formatError } from "@probo/helpers";
|
||||
import { formatError, type GraphQLError } from "@probo/helpers";
|
||||
import { usePageTitle } from "@probo/hooks";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { useToast } from "@probo/ui";
|
||||
@@ -38,8 +38,15 @@ export default function VerifyMagicLinkPagePageMutation() {
|
||||
variables: {
|
||||
input: { token },
|
||||
},
|
||||
onCompleted: (_, errors) => {
|
||||
onCompleted: (_, errors: GraphQLError[] | null) => {
|
||||
if (errors) {
|
||||
for (const err of errors) {
|
||||
if (err.extensions?.code === "ALREADY_AUTHENTICATED") {
|
||||
const pathPrefix = getPathPrefix();
|
||||
window.location.href = pathPrefix ? getPathPrefix() : "/";
|
||||
return;
|
||||
}
|
||||
}
|
||||
toast({
|
||||
title: __("Error"),
|
||||
description: formatError(__("Failed to connect"), errors),
|
||||
|
||||
Reference in New Issue
Block a user