mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-13 21:05:22 +00:00
add login posthog events
This commit is contained in:
parent
07863b2753
commit
f853335ef1
4 changed files with 16 additions and 0 deletions
|
|
@ -10,12 +10,14 @@ import { signIn } from "next-auth/react";
|
||||||
import { verifyCredentialsRequestSchema } from "@/lib/schemas";
|
import { verifyCredentialsRequestSchema } from "@/lib/schemas";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
|
import useCaptureEvent from "@/hooks/useCaptureEvent";
|
||||||
|
|
||||||
interface CredentialsFormProps {
|
interface CredentialsFormProps {
|
||||||
callbackUrl?: string;
|
callbackUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CredentialsForm = ({ callbackUrl }: CredentialsFormProps) => {
|
export const CredentialsForm = ({ callbackUrl }: CredentialsFormProps) => {
|
||||||
|
const captureEvent = useCaptureEvent();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const form = useForm<z.infer<typeof verifyCredentialsRequestSchema>>({
|
const form = useForm<z.infer<typeof verifyCredentialsRequestSchema>>({
|
||||||
resolver: zodResolver(verifyCredentialsRequestSchema),
|
resolver: zodResolver(verifyCredentialsRequestSchema),
|
||||||
|
|
@ -27,6 +29,7 @@ export const CredentialsForm = ({ callbackUrl }: CredentialsFormProps) => {
|
||||||
|
|
||||||
const onSubmit = (values: z.infer<typeof verifyCredentialsRequestSchema>) => {
|
const onSubmit = (values: z.infer<typeof verifyCredentialsRequestSchema>) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
captureEvent("wa_login_with_credentials", {});
|
||||||
signIn("credentials", {
|
signIn("credentials", {
|
||||||
email: values.email,
|
email: values.email,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import { MagicLinkForm } from "./magicLinkForm";
|
||||||
import { CredentialsForm } from "./credentialsForm";
|
import { CredentialsForm } from "./credentialsForm";
|
||||||
import { SourcebotLogo } from "@/app/components/sourcebotLogo";
|
import { SourcebotLogo } from "@/app/components/sourcebotLogo";
|
||||||
import { TextSeparator } from "@/app/components/textSeparator";
|
import { TextSeparator } from "@/app/components/textSeparator";
|
||||||
|
import useCaptureEvent from "@/hooks/useCaptureEvent";
|
||||||
|
|
||||||
interface LoginFormProps {
|
interface LoginFormProps {
|
||||||
callbackUrl?: string;
|
callbackUrl?: string;
|
||||||
|
|
@ -24,6 +25,7 @@ interface LoginFormProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps) => {
|
export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps) => {
|
||||||
|
const captureEvent = useCaptureEvent();
|
||||||
const onSignInWithOauth = useCallback((provider: string) => {
|
const onSignInWithOauth = useCallback((provider: string) => {
|
||||||
signIn(provider, { redirectTo: callbackUrl ?? "/" });
|
signIn(provider, { redirectTo: callbackUrl ?? "/" });
|
||||||
}, [callbackUrl]);
|
}, [callbackUrl]);
|
||||||
|
|
@ -66,6 +68,7 @@ export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps
|
||||||
name="GitHub"
|
name="GitHub"
|
||||||
logo={getCodeHostIcon("github")!}
|
logo={getCodeHostIcon("github")!}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
captureEvent("wa_login_with_github", {});
|
||||||
onSignInWithOauth("github")
|
onSignInWithOauth("github")
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -76,6 +79,7 @@ export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps
|
||||||
name="Google"
|
name="Google"
|
||||||
logo={{ src: googleLogo }}
|
logo={{ src: googleLogo }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
captureEvent("wa_login_with_google", {});
|
||||||
onSignInWithOauth("google")
|
onSignInWithOauth("google")
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import { z } from "zod";
|
||||||
import { signIn } from "next-auth/react";
|
import { signIn } from "next-auth/react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
|
import useCaptureEvent from "@/hooks/useCaptureEvent";
|
||||||
|
|
||||||
const magicLinkSchema = z.object({
|
const magicLinkSchema = z.object({
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
});
|
});
|
||||||
|
|
@ -18,6 +20,7 @@ interface MagicLinkFormProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MagicLinkForm = ({ callbackUrl }: MagicLinkFormProps) => {
|
export const MagicLinkForm = ({ callbackUrl }: MagicLinkFormProps) => {
|
||||||
|
const captureEvent = useCaptureEvent();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const magicLinkForm = useForm<z.infer<typeof magicLinkSchema>>({
|
const magicLinkForm = useForm<z.infer<typeof magicLinkSchema>>({
|
||||||
resolver: zodResolver(magicLinkSchema),
|
resolver: zodResolver(magicLinkSchema),
|
||||||
|
|
@ -28,6 +31,7 @@ export const MagicLinkForm = ({ callbackUrl }: MagicLinkFormProps) => {
|
||||||
|
|
||||||
const onSignIn = (values: z.infer<typeof magicLinkSchema>) => {
|
const onSignIn = (values: z.infer<typeof magicLinkSchema>) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
captureEvent("wa_login_with_magic_link", {});
|
||||||
signIn("nodemailer", { email: values.email, redirectTo: callbackUrl ?? "/" })
|
signIn("nodemailer", { email: values.email, redirectTo: callbackUrl ?? "/" })
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,11 @@ export type PosthogEventMap = {
|
||||||
error: string,
|
error: string,
|
||||||
},
|
},
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
wa_login_with_github: {},
|
||||||
|
wa_login_with_google: {},
|
||||||
|
wa_login_with_magic_link: {},
|
||||||
|
wa_login_with_credentials: {},
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PosthogEvent = keyof PosthogEventMap;
|
export type PosthogEvent = keyof PosthogEventMap;
|
||||||
Loading…
Reference in a new issue