Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d0ed6e

Browse files
committed
Fix login redirect
1 parent 4954a6b commit 2d0ed6e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

site/components/SignIn/SignInForm.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Welcome } from "./Welcome"
99
import { FormTextField } from "../Form"
1010
import * as API from "./../../api"
1111
import { LoadingButton } from "./../Button"
12+
import { firstOrItem } from "../../util/array"
1213

1314
/**
1415
* BuiltInAuthFormValues describes a form using built-in (email/password)
@@ -61,7 +62,14 @@ export const SignInForm: React.FC<SignInProps> = ({
6162
await loginHandler(email, password)
6263
// Tell SWR to invalidate the cache for the user endpoint
6364
await mutate("/api/v2/users/me")
64-
await router.push("/")
65+
66+
let redirect = "/"
67+
if (router.query?.redirect) {
68+
redirect = firstOrItem(router.query.redirect, redirect)
69+
}
70+
71+
console.log("Using redirect: " + redirect)
72+
await router.push(redirect)
6573
} catch (err) {
6674
helpers.setFieldError("password", "The username or password is incorrect.")
6775
}

0 commit comments

Comments
 (0)