mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-30 02:36:30 +02:00
Track login usage
This commit is contained in:
parent
ccc2896b2d
commit
09e35c172e
2 changed files with 8 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
import { usePlausible } from "next-plausible";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { validEmail } from "utils/form-validation";
|
import { validEmail } from "utils/form-validation";
|
||||||
|
@ -12,6 +13,7 @@ const LoginForm: React.VoidFunctionComponent = () => {
|
||||||
const { register, formState, handleSubmit, getValues } =
|
const { register, formState, handleSubmit, getValues } =
|
||||||
useForm<{ email: string }>();
|
useForm<{ email: string }>();
|
||||||
|
|
||||||
|
const plausible = usePlausible();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
return (
|
return (
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
|
@ -23,6 +25,7 @@ const LoginForm: React.VoidFunctionComponent = () => {
|
||||||
{!formState.isSubmitSuccessful ? (
|
{!formState.isSubmitSuccessful ? (
|
||||||
<form
|
<form
|
||||||
onSubmit={handleSubmit(async ({ email }) => {
|
onSubmit={handleSubmit(async ({ email }) => {
|
||||||
|
plausible("Login requested");
|
||||||
await axios.post("/api/login", { email, path: router.asPath });
|
await axios.post("/api/login", { email, path: router.asPath });
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { GetServerSideProps, NextPage } from "next";
|
import { GetServerSideProps, NextPage } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
import { usePlausible } from "next-plausible";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { useTimeoutFn } from "react-use";
|
import { useTimeoutFn } from "react-use";
|
||||||
|
@ -16,12 +17,15 @@ const Page: NextPage<{ success: boolean; redirectTo: string }> = ({
|
||||||
redirectTo,
|
redirectTo,
|
||||||
}) => {
|
}) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const pluasible = usePlausible();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
toast.error("Login failed! Link is expired or invalid");
|
toast.error("Login failed! Link is expired or invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
useTimeoutFn(() => {
|
useTimeoutFn(() => {
|
||||||
|
if (success) {
|
||||||
|
pluasible("Login completed");
|
||||||
|
}
|
||||||
router.replace(redirectTo);
|
router.replace(redirectTo);
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue