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

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix login redirect
  • Loading branch information
bryphe-coder committed Feb 16, 2022
commit 2d0ed6ede045509bbedd1744d18e3bf8a5aadfff
10 changes: 9 additions & 1 deletion site/components/SignIn/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Welcome } from "./Welcome"
import { FormTextField } from "../Form"
import * as API from "./../../api"
import { LoadingButton } from "./../Button"
import { firstOrItem } from "../../util/array"

/**
* BuiltInAuthFormValues describes a form using built-in (email/password)
Expand Down Expand Up @@ -61,7 +62,14 @@ export const SignInForm: React.FC<SignInProps> = ({
await loginHandler(email, password)
// Tell SWR to invalidate the cache for the user endpoint
await mutate("/api/v2/users/me")
await router.push("/")

let redirect = "/"
if (router.query?.redirect) {
redirect = firstOrItem(router.query.redirect, redirect)
}

console.log("Using redirect: " + redirect)
await router.push(redirect)
} catch (err) {
helpers.setFieldError("password", "The username or password is incorrect.")
}
Expand Down