File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 11import { makeStyles } from "@material-ui/core/styles"
22import { FormikContextType , useFormik } from "formik"
3- import { useRouter } from "next/router"
3+ import { NextRouter , useRouter } from "next/router"
44import React from "react"
55import { useSWRConfig } from "swr"
66import * as Yup from "yup"
@@ -63,12 +63,7 @@ export const SignInForm: React.FC<SignInProps> = ({
6363 // Tell SWR to invalidate the cache for the user endpoint
6464 await mutate ( "/api/v2/users/me" )
6565
66- let redirect = "/"
67- if ( router . query ?. redirect ) {
68- redirect = firstOrItem ( router . query . redirect , redirect )
69- }
70-
71- console . log ( "Using redirect: " + redirect )
66+ const redirect = getRedirectFromRouter ( router )
7267 await router . push ( redirect )
7368 } catch ( err ) {
7469 helpers . setFieldError ( "password" , "The username or password is incorrect." )
@@ -125,3 +120,12 @@ export const SignInForm: React.FC<SignInProps> = ({
125120 </ >
126121 )
127122}
123+
124+ const getRedirectFromRouter = ( router : NextRouter ) => {
125+ const defaultRedirect = "/"
126+ if ( router . query ?. redirect ) {
127+ return firstOrItem ( router . query . redirect , defaultRedirect )
128+ } else {
129+ return defaultRedirect
130+ }
131+ }
You can’t perform that action at this time.
0 commit comments