@@ -2,7 +2,7 @@ import { useDisclosure } from '@chakra-ui/react';
2
2
import React from 'react' ;
3
3
4
4
import AuthModal from './AuthModal' ;
5
- import useProfileQuery from './useProfileQuery ' ;
5
+ import useIsAuth from './useIsAuth ' ;
6
6
7
7
interface InjectedProps {
8
8
onClick : ( ) => void ;
@@ -11,51 +11,27 @@ interface InjectedProps {
11
11
interface Props {
12
12
children : ( props : InjectedProps ) => React . ReactNode ;
13
13
onAuthSuccess : ( ) => void ;
14
- ensureEmail ?: boolean ;
15
14
}
16
15
17
- const AuthGuard = ( { children, onAuthSuccess, ensureEmail } : Props ) => {
16
+ const AuthGuard = ( { children, onAuthSuccess } : Props ) => {
18
17
const authModal = useDisclosure ( ) ;
19
- const profileQuery = useProfileQuery ( ) ;
18
+ const isAuth = useIsAuth ( ) ;
20
19
21
20
const handleClick = React . useCallback ( ( ) => {
22
- if ( profileQuery . data ) {
23
- if ( ensureEmail && ! profileQuery . data . email ) {
24
- authModal . onOpen ( ) ;
25
- } else {
26
- onAuthSuccess ( ) ;
27
- }
28
- } else {
29
- authModal . onOpen ( ) ;
30
- }
31
- } , [ authModal , ensureEmail , profileQuery . data , onAuthSuccess ] ) ;
21
+ isAuth ? onAuthSuccess ( ) : authModal . onOpen ( ) ;
22
+ } , [ authModal , isAuth , onAuthSuccess ] ) ;
32
23
33
24
const handleModalClose = React . useCallback ( ( isSuccess ?: boolean ) => {
34
25
if ( isSuccess ) {
35
- if ( ensureEmail && ! profileQuery . data ?. email ) {
36
- // If the user has logged in and has not added an email
37
- // we need to close the modal and open it again
38
- // so the initial screen will be correct
39
- authModal . onClose ( ) ;
40
- window . setTimeout ( ( ) => {
41
- authModal . onOpen ( ) ;
42
- } , 500 ) ;
43
- return ;
44
- }
45
26
onAuthSuccess ( ) ;
46
27
}
47
28
authModal . onClose ( ) ;
48
- } , [ authModal , ensureEmail , profileQuery . data , onAuthSuccess ] ) ;
29
+ } , [ authModal , onAuthSuccess ] ) ;
49
30
50
31
return (
51
32
< >
52
33
{ children ( { onClick : handleClick } ) }
53
- { authModal . isOpen && (
54
- < AuthModal
55
- onClose = { handleModalClose }
56
- initialScreen = { profileQuery . data && ! profileQuery . data . email && ensureEmail ? { type : 'email' } : { type : 'select_method' } }
57
- />
58
- ) }
34
+ { authModal . isOpen && < AuthModal onClose = { handleModalClose } initialScreen = { { type : 'select_method' } } /> }
59
35
</ >
60
36
) ;
61
37
} ;
0 commit comments