Skip to content

Commit 62abcb0

Browse files
committed
Fixed: redirection after login in app router based login page
1 parent 15433b9 commit 62abcb0

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

apps/web/app/(with-contexts)/(with-layout)/login/login-form.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ import {
2828
LOGIN_FORM_LABEL,
2929
LOGIN_FORM_DISCLAIMER,
3030
LOADING,
31-
LOGIN_SUCCESS,
3231
TOAST_TITLE_ERROR,
33-
TOAST_TITLE_SUCCESS,
3432
} from "@/ui-config/strings";
3533
import Link from "next/link";
3634
import { TriangleAlert } from "lucide-react";
35+
import { useRouter } from "next/navigation";
3736

38-
export default function LoginForm() {
37+
export default function LoginForm({ redirectTo }: { redirectTo?: string }) {
3938
const { theme } = useContext(ThemeContext);
4039
const [showCode, setShowCode] = useState(false);
4140
const [email, setEmail] = useState("");
4241
const [code, setCode] = useState("");
4342
const [error, setError] = useState("");
4443
const [loading, setLoading] = useState(false);
4544
const { toast } = useToast();
45+
const router = useRouter();
4646

4747
const requestCode = async function (e: FormEvent) {
4848
e.preventDefault();
@@ -79,10 +79,12 @@ export default function LoginForm() {
7979
if (response?.error) {
8080
setError(`Can't sign you in at this time`);
8181
} else {
82-
toast({
83-
title: TOAST_TITLE_SUCCESS,
84-
description: LOGIN_SUCCESS,
85-
});
82+
// toast({
83+
// title: TOAST_TITLE_SUCCESS,
84+
// description: LOGIN_SUCCESS,
85+
// });
86+
// router.replace(redirectTo || "/dashboard/my-content");
87+
window.location.href = redirectTo || "/dashboard/my-content";
8688
}
8789
} finally {
8890
setLoading(false);

apps/web/ui-config/strings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ export const MAIL_REQUEST_FORM_REASON_PLACEHOLDER =
596596
"Please be as detailed as possible. This will help us review your application better.";
597597
export const DASHBOARD_SELECT_HEADER = "Duration";
598598
export const DELETE_EMAIL_MENU = "Delete";
599-
export const LOGIN_SUCCESS = "Login successful. Redirecting...";
600599
export const OVERVIEW_HEADER = "Overview";
601600
export const HELP_HEADER = "Help";
602601
export const COMMUNITY_HEADER = "Community";

packages/page-blocks/src/blocks/header/widget/index.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
spacingBetweenLinks as defaultSpacingBetweenLinks,
1616
linkFontWeight as defaultLinkFontWeight,
1717
} from "../defaults";
18-
import { Header4, Section } from "@courselit/page-primitives";
18+
import {
19+
Header4,
20+
Section,
21+
Link as PrimitiveLink,
22+
} from "@courselit/page-primitives";
1923
import PageLink from "./link";
2024
import clsx from "clsx";
2125
import { ThemeStyle } from "@courselit/page-models";
@@ -144,7 +148,18 @@ export default function Widget({ state, settings }: WidgetProps<Settings>) {
144148
href={"/dashboard"}
145149
className={linkClasses}
146150
>
147-
Dashboard
151+
<PrimitiveLink
152+
theme={overiddenTheme}
153+
style={{
154+
color:
155+
settings.linkColor ||
156+
overiddenTheme?.colors
157+
?.text,
158+
}}
159+
className="!no-underline"
160+
>
161+
Dashboard
162+
</PrimitiveLink>
148163
</AppLink>
149164
</MenuItem2>
150165
)}
@@ -157,7 +172,20 @@ export default function Widget({ state, settings }: WidgetProps<Settings>) {
157172
}
158173
className={linkClasses}
159174
>
160-
{state.auth.guest ? "Login" : "Logout"}
175+
<PrimitiveLink
176+
theme={overiddenTheme}
177+
style={{
178+
color:
179+
settings.linkColor ||
180+
overiddenTheme?.colors
181+
?.text,
182+
}}
183+
className="!no-underline"
184+
>
185+
{state.auth.guest
186+
? "Login"
187+
: "Logout"}
188+
</PrimitiveLink>
161189
</AppLink>
162190
</MenuItem2>
163191
</Menu>

0 commit comments

Comments
 (0)