@@ -43,6 +43,13 @@ const Login = () => {
43
43
const [ isLoading , setIsLoading ] = React . useState ( true ) ;
44
44
const { login, loginGoogle, loginError } = useAuth ( ) ;
45
45
const [ recoveryCodes , setRecoveryCodes ] = React . useState < string [ ] > ( [ ] ) ;
46
+ const [ isRendered , setIsRendered ] = React . useState < boolean > ( false ) ;
47
+ const signinDiv = React . useCallback ( ( node : HTMLDivElement | null ) => {
48
+ if ( node !== null ) {
49
+ setIsRendered ( true ) ;
50
+ }
51
+ } , [ ] ) ;
52
+
46
53
const iconStyles = {
47
54
color : appColors . white ,
48
55
width : { xs : "30%" , lg : "40%" } ,
@@ -63,37 +70,39 @@ const Login = () => {
63
70
} ;
64
71
65
72
useEffect ( ( ) => {
66
- const fetchRegisterPrompt = async ( ) => {
67
- const data = await getRegisterOption ( ) ;
68
- setShowAdminAlertModal ( data . require_register ) ;
69
- setIsLoading ( false ) ;
70
- } ;
71
- fetchRegisterPrompt ( ) ;
72
73
const handleCredentialResponse = ( response : any ) => {
73
74
loginGoogle ( {
74
75
client_id : response . client_id ,
75
76
credential : response . credential ,
76
77
} ) ;
77
78
} ;
78
- window . google . accounts . id . initialize ( {
79
- client_id : NEXT_PUBLIC_GOOGLE_LOGIN_CLIENT_ID ,
80
- callback : ( data ) => handleCredentialResponse ( data ) ,
81
- state_cookie_domain : "https://example.com" ,
82
- } ) ;
83
-
84
- const signinDiv = document . getElementById ( "signinDiv" ) ;
85
-
86
- if ( signinDiv ) {
87
- window . google . accounts . id . renderButton ( signinDiv , {
88
- type : "standard" ,
89
- shape : "pill" ,
90
- theme : "outline" ,
91
- size : "large" ,
92
- width : 275 ,
79
+ if ( isRendered ) {
80
+ window . google . accounts . id . initialize ( {
81
+ client_id : NEXT_PUBLIC_GOOGLE_LOGIN_CLIENT_ID ,
82
+ callback : ( data ) => handleCredentialResponse ( data ) ,
83
+ state_cookie_domain : "https://example.com" ,
93
84
} ) ;
85
+ const signinDivId = document . getElementById ( "signinDiv" ) ;
86
+ if ( signinDivId ) {
87
+ window . google . accounts . id . renderButton ( signinDivId , {
88
+ type : "standard" ,
89
+ shape : "pill" ,
90
+ theme : "outline" ,
91
+ size : "large" ,
92
+ width : 275 ,
93
+ } ) ;
94
+ }
94
95
}
95
- } , [ ] ) ;
96
+ } , [ isRendered ] ) ;
96
97
98
+ useEffect ( ( ) => {
99
+ const fetchRegisterPrompt = async ( ) => {
100
+ const data = await getRegisterOption ( ) ;
101
+ setShowAdminAlertModal ( data . require_register ) ;
102
+ setIsLoading ( false ) ;
103
+ } ;
104
+ fetchRegisterPrompt ( ) ;
105
+ } , [ ] ) ;
97
106
useEffect ( ( ) => {
98
107
if ( recoveryCodes . length > 0 ) {
99
108
setShowConfirmationModal ( true ) ;
@@ -348,7 +357,7 @@ const Login = () => {
348
357
alignItems = "center"
349
358
justifyContent = "center"
350
359
>
351
- < div id = "signinDiv" />
360
+ < div ref = { signinDiv } id = "signinDiv" />
352
361
< Layout . Spacer multiplier = { 2.5 } />
353
362
< Box display = "flex" alignItems = "center" width = "100%" >
354
363
< Box flexGrow = { 1 } height = "1px" bgcolor = "lightgrey" />
@@ -360,6 +369,7 @@ const Login = () => {
360
369
< Layout . Spacer multiplier = { 1.5 } />
361
370
</ Box >
362
371
) }
372
+
363
373
< Box
364
374
component = "form"
365
375
noValidate
0 commit comments