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