|
1 | | -importtype{FC}from"react"; |
| 1 | +import{useEffect,typeFC}from"react"; |
2 | 2 | import{Helmet}from"react-helmet-async"; |
3 | 3 | import{useQuery}from"react-query"; |
4 | 4 | import{Navigate,useLocation,useNavigate}from"react-router-dom"; |
@@ -26,10 +26,21 @@ export const LoginPage: FC = () => { |
26 | 26 | constredirectTo=retrieveRedirect(location.search); |
27 | 27 | constapplicationName=getApplicationName(); |
28 | 28 | constnavigate=useNavigate(); |
29 | | - |
30 | 29 | const{ metadata}=useEmbeddedMetadata(); |
31 | 30 | constbuildInfoQuery=useQuery(buildInfo(metadata["build-info"])); |
32 | 31 |
|
| 32 | +useEffect(()=>{ |
| 33 | +if(!buildInfoQuery.data||isSignedIn){ |
| 34 | +// isSignedIn already tracks with window.href! |
| 35 | +return; |
| 36 | +} |
| 37 | +// This uses `navigator.sendBeacon`, so navigating away will not prevent it! |
| 38 | +sendDeploymentEvent(buildInfoQuery.data,{ |
| 39 | +type:"deployment_login", |
| 40 | +user_id:user?.id, |
| 41 | +}); |
| 42 | +},[isSignedIn,buildInfoQuery.data,user?.id]); |
| 43 | + |
33 | 44 | if(isSignedIn){ |
34 | 45 | if(buildInfoQuery.data){ |
35 | 46 | // This uses `navigator.sendBeacon`, so window.href |
@@ -85,15 +96,6 @@ export const LoginPage: FC = () => { |
85 | 96 | isSigningIn={isSigningIn} |
86 | 97 | onSignIn={async({ email, password})=>{ |
87 | 98 | awaitsignIn(email,password); |
88 | | -if(buildInfoQuery.data){ |
89 | | -// This uses `navigator.sendBeacon`, so navigating away |
90 | | -// will not prevent it! |
91 | | -sendDeploymentEvent(buildInfoQuery.data,{ |
92 | | -type:"deployment_login", |
93 | | -user_id:user?.id, |
94 | | -}); |
95 | | -} |
96 | | - |
97 | 99 | navigate("/"); |
98 | 100 | }} |
99 | 101 | /> |
|