Skip to content

Commit e15e92c

Browse files
committed
feat: preserve login params in forgot password screen
1 parent 3906e50 commit e15e92c

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

frontend/src/components/auth/login-form.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface Props {
1717
onSubmit: (data: LoginSchema) => void;
1818
loading?: boolean;
1919
formId?: string;
20+
params?: string;
2021
}
2122

2223
export const LoginForm = (props: Props) => {
@@ -71,6 +72,12 @@ export const LoginForm = (props: Props) => {
7172
</FormControl>
7273
<a
7374
href="/forgot-password"
75+
onClick={(e) => {
76+
e.preventDefault();
77+
window.location.replace(
78+
`/forgot-password${props.params ? `${props.params}` : ""}`,
79+
);
80+
}}
7481
className="text-muted-foreground hover:text-muted-foreground/80 text-sm absolute right-0 bottom-[2.565rem]" // 2.565 is *just* perfect
7582
>
7683
{t("forgotPasswordTitle")}

frontend/src/lib/i18n/locales/en-US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@
7979
"profileScopeName": "Profile",
8080
"profileScopeDescription": "Allows the app to access your profile information.",
8181
"groupsScopeName": "Groups",
82-
"groupsScopeDescription": "Allows the app to access your group information."
82+
"groupsScopeDescription": "Allows the app to access your group information.",
83+
"backToLoginButton": "Back to login"
8384
}

frontend/src/lib/i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@
7979
"profileScopeName": "Profile",
8080
"profileScopeDescription": "Allows the app to access your profile information.",
8181
"groupsScopeName": "Groups",
82-
"groupsScopeDescription": "Allows the app to access your group information."
82+
"groupsScopeDescription": "Allows the app to access your group information.",
83+
"backToLoginButton": "Back to login"
8384
}

frontend/src/pages/forgot-password-page.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import { Button } from "@/components/ui/button";
1010
import { useAppContext } from "@/context/app-context";
1111
import { useTranslation } from "react-i18next";
1212
import Markdown from "react-markdown";
13-
import { useNavigate } from "react-router";
13+
import { useLocation } from "react-router";
1414

1515
export const ForgotPasswordPage = () => {
1616
const { forgotPasswordMessage } = useAppContext();
1717
const { t } = useTranslation();
18-
const navigate = useNavigate();
18+
const { search } = useLocation();
19+
const searchParams = new URLSearchParams(search);
1920

2021
return (
2122
<Card>
@@ -36,10 +37,13 @@ export const ForgotPasswordPage = () => {
3637
className="w-full"
3738
variant="outline"
3839
onClick={() => {
39-
navigate("/login");
40+
const eparams = searchParams.toString();
41+
window.location.replace(
42+
`/login${eparams.length > 0 ? `?${eparams}` : ""}`,
43+
);
4044
}}
4145
>
42-
{t("notFoundButton")}
46+
{t("backToLoginButton")}
4347
</Button>
4448
</CardFooter>
4549
</Card>

frontend/src/pages/login-page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ export const LoginPage = () => {
264264
onSubmit={(values) => loginMutate(values)}
265265
loading={loginIsPending || oauthIsPending}
266266
formId={formId}
267+
params={(() => {
268+
const eparams = searchParams.toString();
269+
return eparams.length > 0 ? `?${eparams}` : "";
270+
})()}
267271
/>
268272
)}
269273
{providers.length == 0 && (

0 commit comments

Comments
 (0)