feat: added posthog

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-12-25 13:53:41 -08:00
parent d9e6947fbd
commit 518958e9a7
15 changed files with 526 additions and 17 deletions

View file

@ -10,6 +10,7 @@ import { toast } from "sonner";
import { loginMutationAtom } from "@/atoms/auth/auth-mutation.atoms";
import { getAuthErrorDetails, isNetworkError, shouldRetry } from "@/lib/auth-errors";
import { ValidationError } from "@/lib/error";
import { trackLoginAttempt, trackLoginFailure, trackLoginSuccess } from "@/lib/posthog/events";
export function LocalLoginForm() {
const t = useTranslations("auth");
@ -37,6 +38,9 @@ export function LocalLoginForm() {
e.preventDefault();
setError({ title: null, message: null }); // Clear any previous errors
// Track login attempt
trackLoginAttempt("local");
// Show loading toast
const loadingToast = toast.loading(tCommon("loading"));
@ -47,6 +51,9 @@ export function LocalLoginForm() {
grant_type: "password",
});
// Track successful login
trackLoginSuccess("local");
// Success toast
toast.success(t("login_success"), {
id: loadingToast,
@ -60,6 +67,7 @@ export function LocalLoginForm() {
}, 500);
} catch (err) {
if (err instanceof ValidationError) {
trackLoginFailure("local", err.message);
setError({ title: err.name, message: err.message });
toast.error(err.name, {
id: loadingToast,
@ -78,6 +86,9 @@ export function LocalLoginForm() {
errorCode = "NETWORK_ERROR";
}
// Track login failure
trackLoginFailure("local", errorCode);
// Get detailed error information from auth-errors utility
const errorDetails = getAuthErrorDetails(errorCode);