mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: track login page correctly (#13618)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { FC } from "react";
|
||||
import { useEffect, type FC } from "react";
|
||||
import { Helmet } from "react-helmet-async";
|
||||
import { useQuery } from "react-query";
|
||||
import { Navigate, useLocation, useNavigate } from "react-router-dom";
|
||||
@@ -26,10 +26,21 @@ export const LoginPage: FC = () => {
|
||||
const redirectTo = retrieveRedirect(location.search);
|
||||
const applicationName = getApplicationName();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { metadata } = useEmbeddedMetadata();
|
||||
const buildInfoQuery = useQuery(buildInfo(metadata["build-info"]));
|
||||
|
||||
useEffect(() => {
|
||||
if (!buildInfoQuery.data || isSignedIn) {
|
||||
// isSignedIn already tracks with window.href!
|
||||
return;
|
||||
}
|
||||
// This uses `navigator.sendBeacon`, so navigating away will not prevent it!
|
||||
sendDeploymentEvent(buildInfoQuery.data, {
|
||||
type: "deployment_login",
|
||||
user_id: user?.id,
|
||||
});
|
||||
}, [isSignedIn, buildInfoQuery.data, user?.id]);
|
||||
|
||||
if (isSignedIn) {
|
||||
if (buildInfoQuery.data) {
|
||||
// This uses `navigator.sendBeacon`, so window.href
|
||||
@@ -85,15 +96,6 @@ export const LoginPage: FC = () => {
|
||||
isSigningIn={isSigningIn}
|
||||
onSignIn={async ({ email, password }) => {
|
||||
await signIn(email, password);
|
||||
if (buildInfoQuery.data) {
|
||||
// This uses `navigator.sendBeacon`, so navigating away
|
||||
// will not prevent it!
|
||||
sendDeploymentEvent(buildInfoQuery.data, {
|
||||
type: "deployment_login",
|
||||
user_id: user?.id,
|
||||
});
|
||||
}
|
||||
|
||||
navigate("/");
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user