Guides / Signups & Auth
npm install logit
Create app/lib/logit.server.ts (the .server.ts suffix keeps it out of the client bundle):
import { init } from "logit";
export const logit = init({ token: process.env.LOGIT_API_KEY! });
// app/routes/signup.tsx
import type { ActionFunctionArgs } from "@remix-run/node";
import { logit } from "~/lib/logit.server";
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData();
const email = String(formData.get("email"));
const plan = String(formData.get("plan") ?? "free");
// ... persist user
await logit.now("signups", {
event: "New user signed up",
description: `${email} joined on ${plan}`,
icon: "👤",
notify: true,
tags: { plan, source: "signup-form" },
metadata: { email },
});
return { ok: true };
}
// app/routes/auth.callback.ts
import type { LoaderFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { logit } from "~/lib/logit.server";
export async function loader({ request }: LoaderFunctionArgs) {
// ... handle OAuth, create user
await logit.now("signups", {
event: "New user via OAuth",
description: user.email,
icon: "👤",
notify: true,
tags: { provider: "github" },
metadata: { email: user.email },
});
return redirect("/dashboard");
}
.server.ts file — Remix automatically strips it from the browser bundle.logit.now() after you've successfully written the user to the database, not before.Try LogIt free
7-day trial. No credit card required.