1
+ import { useApolloClient } from '@apollo/client'
2
+ import { Divider , LoadingSpinner } from '@pluralsh/design-system'
3
+ import { Box , Collapsible , Form , Text } from 'grommet'
4
+ import { A , Button , Div , Flex , Icon } from 'honorable'
5
+ import queryString from 'query-string'
1
6
import {
2
7
RefObject ,
3
8
createElement ,
@@ -6,16 +11,11 @@ import {
6
11
useRef ,
7
12
useState ,
8
13
} from 'react'
9
- import { Box , Collapsible , Form , Text } from 'grommet'
10
- import { Divider , LoadingSpinner } from '@pluralsh/design-system'
11
- import { useApolloClient } from '@apollo/client'
12
- import { Link , useLocation , useNavigate , useParams } from 'react-router-dom'
13
- import queryString from 'query-string'
14
- import { A , Button , Div , Flex , Icon } from 'honorable'
15
14
import {
16
15
GoogleReCaptchaProvider ,
17
16
useGoogleReCaptcha ,
18
17
} from 'react-google-recaptcha-v3'
18
+ import { Link , useLocation , useNavigate , useParams } from 'react-router-dom'
19
19
import styled , { useTheme } from 'styled-components'
20
20
21
21
import {
@@ -31,23 +31,23 @@ import {
31
31
import { WelcomeHeader } from '../utils/WelcomeHeader'
32
32
33
33
import { fetchToken , setToken } from '../../helpers/authentication'
34
- import { Alert , AlertStatus , GqlError } from '../utils/Alert'
35
- import { PLURAL_MARK_WHITE } from '../constants'
36
34
import { host } from '../../helpers/hostname'
37
- import { useHistory } from '../../router'
35
+ import { PLURAL_MARK_WHITE } from '../constants'
36
+ import { Alert , AlertStatus , GqlError } from '../utils/Alert'
38
37
38
+ import { getLocalReturnUrl } from './utils'
39
39
import { isValidEmail } from '../../utils/email'
40
40
41
+ import { finishedDeviceLogin } from './DeviceLoginNotif'
42
+ import { LabelledInput } from './LabelledInput'
43
+ import { LOGIN_BREAKPOINT , LoginPortal } from './LoginPortal'
41
44
import {
42
45
METHOD_ICONS ,
43
46
saveChallenge ,
44
47
saveDeviceToken ,
45
48
wipeChallenge ,
46
49
wipeDeviceToken ,
47
50
} from './utils'
48
- import { finishedDeviceLogin } from './DeviceLoginNotif'
49
- import { LabelledInput } from './LabelledInput'
50
- import { LOGIN_BREAKPOINT , LoginPortal } from './LoginPortal'
51
51
52
52
export function PasswordlessLogin ( ) {
53
53
const { token } = useParams ( )
@@ -120,7 +120,7 @@ export function handleOauthChallenge(client, challenge) {
120
120
}
121
121
122
122
function LoginPoller ( { challenge, token, deviceToken } : any ) {
123
- const history = useHistory ( )
123
+ const navigate = useNavigate ( )
124
124
const client = useApolloClient ( )
125
125
const [ success , setSuccess ] = useState ( false )
126
126
@@ -145,7 +145,7 @@ function LoginPoller({ challenge, token, deviceToken }: any) {
145
145
if ( challenge ) {
146
146
handleOauthChallenge ( client , challenge )
147
147
} else {
148
- history . navigate ( '/' )
148
+ navigate ( getLocalReturnUrl ( ) )
149
149
}
150
150
}
151
151
)
@@ -255,7 +255,6 @@ function LoginInternal() {
255
255
const navigate = useNavigate ( )
256
256
const [ state , setState ] = useState < LoginState > ( State . Initial )
257
257
const prevState = useRef < LoginState > ( State . Initial )
258
- const history = useHistory ( )
259
258
const client = useApolloClient ( )
260
259
const location = useLocation ( )
261
260
const jwt = fetchToken ( )
@@ -312,7 +311,7 @@ function LoginInternal() {
312
311
if ( challenge ) {
313
312
handleOauthChallenge ( client , challenge )
314
313
} else {
315
- history . navigate ( '/' )
314
+ navigate ( getLocalReturnUrl ( ) )
316
315
}
317
316
} ,
318
317
} )
@@ -392,7 +391,7 @@ function LoginInternal() {
392
391
setRan ( true )
393
392
handleOauthChallenge ( client , challenge )
394
393
} else if ( ! deviceToken && ! challenge && jwt ) {
395
- history . navigate ( '/' )
394
+ navigate ( getLocalReturnUrl ( ) )
396
395
}
397
396
} , [ challenge , deviceToken , history , client , jwt , ran , setRan ] )
398
397
0 commit comments