File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { makeStyles } from "@material-ui/core/styles"
2
2
import { FormikContextType , useFormik } from "formik"
3
- import { useRouter } from "next/router"
3
+ import { NextRouter , useRouter } from "next/router"
4
4
import React from "react"
5
5
import { useSWRConfig } from "swr"
6
6
import * as Yup from "yup"
@@ -63,12 +63,7 @@ export const SignInForm: React.FC<SignInProps> = ({
63
63
// Tell SWR to invalidate the cache for the user endpoint
64
64
await mutate ( "/api/v2/users/me" )
65
65
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 )
72
67
await router . push ( redirect )
73
68
} catch ( err ) {
74
69
helpers . setFieldError ( "password" , "The username or password is incorrect." )
@@ -125,3 +120,12 @@ export const SignInForm: React.FC<SignInProps> = ({
125
120
</ >
126
121
)
127
122
}
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