Skip to content

Commit 81d61a0

Browse files
committed
fix(frontend): redirects improvements...
1 parent e1e0fb7 commit 81d61a0

File tree

9 files changed

+59
-124
lines changed

9 files changed

+59
-124
lines changed

autogpt_platform/frontend/src/app/(no-navbar)/onboarding/4-agent/page.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
"use client";
2+
import { StoreAgentDetails } from "@/lib/autogpt-server-api";
3+
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
4+
import { isEmptyOrWhitespace } from "@/lib/utils";
5+
import { useRouter } from "next/navigation";
6+
import { useEffect, useState } from "react";
7+
import { useOnboarding } from "../../../../providers/onboarding/onboarding-provider";
8+
import OnboardingAgentCard from "../components/OnboardingAgentCard";
29
import OnboardingButton from "../components/OnboardingButton";
310
import {
411
OnboardingFooter,
512
OnboardingHeader,
613
OnboardingStep,
714
} from "../components/OnboardingStep";
815
import { OnboardingText } from "../components/OnboardingText";
9-
import OnboardingAgentCard from "../components/OnboardingAgentCard";
10-
import { useEffect, useState } from "react";
11-
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
12-
import { StoreAgentDetails } from "@/lib/autogpt-server-api";
13-
import { isEmptyOrWhitespace } from "@/lib/utils";
14-
import { useOnboarding } from "../../../../providers/onboarding/onboarding-provider";
15-
import router from "next/router";
1616

1717
export default function Page() {
1818
const { state, updateState, completeStep } = useOnboarding(4, "INTEGRATIONS");
1919
const [agents, setAgents] = useState<StoreAgentDetails[]>([]);
2020
const api = useBackendAPI();
21+
const router = useRouter();
2122

2223
useEffect(() => {
2324
api.getOnboardingAgents().then((agents) => {
2425
if (agents.length < 2) {
2526
completeStep("CONGRATS");
26-
router.push("/onboarding");
27+
router.replace("/");
2728
}
2829
setAgents(agents);
2930
});

autogpt_platform/frontend/src/app/(no-navbar)/onboarding/page.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
2-
import { useEffect } from "react";
3-
import { useRouter } from "next/navigation";
4-
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
52
import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
3+
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
4+
import { useRouter } from "next/navigation";
5+
import { useEffect } from "react";
66

77
export default function OnboardingPage() {
88
const router = useRouter();
@@ -14,15 +14,15 @@ export default function OnboardingPage() {
1414
// Check if onboarding is enabled
1515
const isEnabled = await api.isOnboardingEnabled();
1616
if (!isEnabled) {
17-
router.push("/");
17+
router.replace("/");
1818
return;
1919
}
2020

2121
const onboarding = await api.getUserOnboarding();
2222

2323
// Handle completed onboarding
2424
if (onboarding.completedSteps.includes("GET_RESULTS")) {
25-
router.push("/");
25+
router.replace("/");
2626
return;
2727
}
2828

@@ -33,13 +33,13 @@ export default function OnboardingPage() {
3333
const libraryAgent = await api.addMarketplaceAgentToLibrary(
3434
onboarding.selectedStoreListingVersionId,
3535
);
36-
router.push(`/library/agents/${libraryAgent.id}`);
36+
router.replace(`/library/agents/${libraryAgent.id}`);
3737
} catch (error) {
3838
console.error("Failed to add agent to library:", error);
39-
router.push("/library");
39+
router.replace("/library");
4040
}
4141
} else {
42-
router.push("/library");
42+
router.replace("/library");
4343
}
4444
return;
4545
}
@@ -79,7 +79,7 @@ export default function OnboardingPage() {
7979
router.push("/onboarding/1-welcome");
8080
} catch (error) {
8181
console.error("Failed to determine onboarding step:", error);
82-
router.push("/");
82+
router.replace("/");
8383
}
8484
}
8585

autogpt_platform/frontend/src/app/(platform)/login/page.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client";
2+
import { Form, FormField } from "@/components/__legacy__/ui/form";
23
import { Button } from "@/components/atoms/Button/Button";
34
import { Input } from "@/components/atoms/Input/Input";
45
import { Link } from "@/components/atoms/Link/Link";
@@ -7,10 +8,9 @@ import AuthFeedback from "@/components/auth/AuthFeedback";
78
import { EmailNotAllowedModal } from "@/components/auth/EmailNotAllowedModal";
89
import { GoogleOAuthButton } from "@/components/auth/GoogleOAuthButton";
910
import Turnstile from "@/components/auth/Turnstile";
10-
import { Form, FormField } from "@/components/__legacy__/ui/form";
11+
import { environment } from "@/services/environment";
1112
import { LoadingLogin } from "./components/LoadingLogin";
1213
import { useLoginPage } from "./useLoginPage";
13-
import { environment } from "@/services/environment";
1414

1515
export default function LoginPage() {
1616
const {
@@ -20,18 +20,16 @@ export default function LoginPage() {
2020
turnstile,
2121
captchaKey,
2222
isLoading,
23-
isRedirecting,
2423
isCloudEnv,
2524
isUserLoading,
26-
isGoogleLoading,
2725
showNotAllowedModal,
2826
isSupabaseAvailable,
2927
handleSubmit,
3028
handleProviderLogin,
3129
handleCloseNotAllowedModal,
3230
} = useLoginPage();
3331

34-
if (isUserLoading || user || isRedirecting) {
32+
if (isUserLoading || user) {
3533
return <LoadingLogin />;
3634
}
3735

@@ -111,7 +109,7 @@ export default function LoginPage() {
111109
{isCloudEnv ? (
112110
<GoogleOAuthButton
113111
onClick={() => handleProviderLogin("google")}
114-
isLoading={isGoogleLoading}
112+
isLoading={isLoading}
115113
disabled={isLoading}
116114
/>
117115
) : null}

autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ export function useLoginPage() {
1919
const returnUrl = searchParams.get("returnUrl");
2020
const { toast } = useToast();
2121
const [isLoading, setIsLoading] = useState(false);
22-
const [isGoogleLoading, setIsGoogleLoading] = useState(false);
2322
const [showNotAllowedModal, setShowNotAllowedModal] = useState(false);
24-
const [isRedirecting, setIsRedirecting] = useState(false);
2523
const isCloudEnv = environment.isCloud();
2624
const isVercelPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === "preview";
2725

@@ -45,15 +43,15 @@ export function useLoginPage() {
4543
}, [turnstile]);
4644

4745
async function handleProviderLogin(provider: LoginProvider) {
48-
setIsGoogleLoading(true);
46+
setIsLoading(true);
4947

5048
if (isCloudEnv && !turnstile.verified && !isVercelPreview) {
5149
toast({
5250
title: "Please complete the CAPTCHA challenge.",
5351
variant: "info",
5452
});
5553

56-
setIsGoogleLoading(false);
54+
setIsLoading(false);
5755
resetCaptcha();
5856
return;
5957
}
@@ -67,24 +65,14 @@ export function useLoginPage() {
6765

6866
if (!response.ok) {
6967
const { error } = await response.json();
70-
if (error === "not_allowed") {
71-
setShowNotAllowedModal(true);
72-
} else {
73-
setFeedback(error || "Failed to start OAuth flow");
74-
}
75-
resetCaptcha();
76-
setIsGoogleLoading(false);
77-
return;
68+
throw new Error(error || "Failed to start OAuth flow");
7869
}
7970

8071
const { url } = await response.json();
81-
if (url) {
82-
setIsRedirecting(true);
83-
window.location.href = url as string;
84-
}
72+
if (url) window.location.href = url as string;
8573
} catch (error) {
8674
resetCaptcha();
87-
setIsGoogleLoading(false);
75+
setIsLoading(false);
8876
setFeedback(
8977
error instanceof Error ? error.message : "Failed to start OAuth flow",
9078
);
@@ -93,6 +81,7 @@ export function useLoginPage() {
9381

9482
async function handleLogin(data: z.infer<typeof loginFormSchema>) {
9583
setIsLoading(true);
84+
9685
if (isCloudEnv && !turnstile.verified && !isVercelPreview) {
9786
toast({
9887
title: "Please complete the CAPTCHA challenge.",
@@ -129,26 +118,12 @@ export function useLoginPage() {
129118
const result = await response.json();
130119

131120
if (!response.ok) {
132-
toast({
133-
title: result?.error || "Login failed",
134-
variant: "destructive",
135-
});
136-
setIsLoading(false);
137-
resetCaptcha();
138-
turnstile.reset();
139-
return;
121+
throw new Error(result?.error || "Login failed");
140122
}
141123

142-
await supabase?.auth.refreshSession();
143-
setIsLoading(false);
144-
setFeedback(null);
145-
146124
// Prioritize returnUrl from query params over backend's onboarding logic
147125
const next = computeReturnURL(returnUrl, result);
148-
if (next) {
149-
setIsRedirecting(true);
150-
router.push(next);
151-
}
126+
if (next) router.replace(next);
152127
} catch (error) {
153128
toast({
154129
title:
@@ -170,10 +145,8 @@ export function useLoginPage() {
170145
captchaKey,
171146
user,
172147
isLoading,
173-
isRedirecting,
174148
isCloudEnv,
175149
isUserLoading,
176-
isGoogleLoading,
177150
showNotAllowedModal,
178151
isSupabaseAvailable: !!supabase,
179152
handleSubmit: form.handleSubmit(handleLogin),

autogpt_platform/frontend/src/app/(platform)/signup/page.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
"use client";
22

3+
import { Checkbox } from "@/components/__legacy__/ui/checkbox";
4+
import {
5+
Form,
6+
FormControl,
7+
FormField,
8+
FormItem,
9+
FormLabel,
10+
} from "@/components/__legacy__/ui/form";
311
import { Button } from "@/components/atoms/Button/Button";
412
import { Input } from "@/components/atoms/Input/Input";
513
import { Link } from "@/components/atoms/Link/Link";
@@ -9,18 +17,10 @@ import AuthFeedback from "@/components/auth/AuthFeedback";
917
import { EmailNotAllowedModal } from "@/components/auth/EmailNotAllowedModal";
1018
import { GoogleOAuthButton } from "@/components/auth/GoogleOAuthButton";
1119
import Turnstile from "@/components/auth/Turnstile";
12-
import { Checkbox } from "@/components/__legacy__/ui/checkbox";
13-
import {
14-
Form,
15-
FormControl,
16-
FormField,
17-
FormItem,
18-
FormLabel,
19-
} from "@/components/__legacy__/ui/form";
20+
import { environment } from "@/services/environment";
2021
import { WarningOctagonIcon } from "@phosphor-icons/react/dist/ssr";
2122
import { LoadingSignup } from "./components/LoadingSignup";
2223
import { useSignupPage } from "./useSignupPage";
23-
import { environment } from "@/services/environment";
2424

2525
export default function SignupPage() {
2626
const {
@@ -32,16 +32,14 @@ export default function SignupPage() {
3232
isLoading,
3333
isCloudEnv,
3434
isUserLoading,
35-
isRedirecting,
36-
isGoogleLoading,
3735
showNotAllowedModal,
3836
isSupabaseAvailable,
3937
handleSubmit,
4038
handleProviderSignup,
4139
handleCloseNotAllowedModal,
4240
} = useSignupPage();
4341

44-
if (isUserLoading || isLoggedIn || isRedirecting) {
42+
if (isUserLoading || isLoggedIn) {
4543
return <LoadingSignup />;
4644
}
4745

@@ -189,7 +187,7 @@ export default function SignupPage() {
189187
{isCloudEnv ? (
190188
<GoogleOAuthButton
191189
onClick={() => handleProviderSignup("google")}
192-
isLoading={isGoogleLoading}
190+
isLoading={isLoading}
193191
disabled={isLoading}
194192
/>
195193
) : null}

0 commit comments

Comments
 (0)