🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
email organization invites (#272)
Bill Yang31951e613dcc
diff --git a/.env.example b/.env.exampleindex bc38d70f4..a1d429dbd 100644--- a/.env.example+++ b/.env.example@@ -23,3 +23,5 @@ CLICKHOUSE_PASSWORD=frogPOSTGRES_DB=analyticsPOSTGRES_USER=frogPOSTGRES_PASSWORD=frog++RESEND_API_KEY=rs_XXXXXXXdiff --git a/client/src/api/admin/organizations.ts b/client/src/api/admin/organizations.tsindex 66d73f946..581c373c7 100644--- a/client/src/api/admin/organizations.ts+++ b/client/src/api/admin/organizations.ts@@ -1,6 +1,7 @@import { useQuery } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";import { authedFetchWithError } from "../utils";+import { authClient } from "../../lib/auth";export type UserOrganization = {id: string;@@ -22,3 +23,22 @@ export function useUserOrganizations() {queryFn: getUserOrganizations,});}++export function useOrganizationInvitations(organizationId: string) {+ return useQuery({+ queryKey: ["invitations", organizationId],+ queryFn: async () => {+ const invitations = await authClient.organization.listInvitations({+ query: {+ organizationId,+ },+ });++ if (invitations.error) {+ throw new Error(invitations.error.message);+ }++ return invitations.data;+ },+ });+}diff --git a/client/src/app/invitation/components/login.tsx b/client/src/app/invitation/components/login.tsxnew file mode 100644index 000000000..f13d1c8ed--- /dev/null+++ b/client/src/app/invitation/components/login.tsx@@ -0,0 +1,143 @@+"use client";++import { GithubLogo, GoogleLogo } from "@phosphor-icons/react/dist/ssr";+import { AlertCircle } from "lucide-react";+import { useState } from "react";+import {+ Alert,+ AlertDescription,+ AlertTitle,+} from "../../../components/ui/alert";+import { Button } from "../../../components/ui/button";+import { Input } from "../../../components/ui/input";+import { Label } from "../../../components/ui/label";+import { authClient } from "../../../lib/auth";+import { IS_CLOUD } from "../../../lib/const";+import { userStore } from "../../../lib/userStore";++interface LoginProps {+ inviterEmail?: string | null;+ organization?: string | null;+}++export function Login({ inviterEmail, organization }: LoginProps) {+ const [isLoading, setIsLoading] = useState(false);+ const [error, setError] = useState<string>("");+ const [email, setEmail] = useState("");+ const [password, setPassword] = useState("");++ const handleLogin = async (e: React.FormEvent) => {+ e.preventDefault();+ setIsLoading(true);+ setError("");++ try {+ const { data, error } = await authClient.signIn.email({+ email,+ password,+ });++ if (data?.user) {+ userStore.setState({+ user: data.user,+ });+ // Force reload to show the AcceptInvitationInner component+ window.location.reload();+ }++ if (error) {+ setError(error.message || "An error occurred during login");+ }+ } catch (error) {+ setError(String(error));+ } finally {+ setIsLoading(false);+ }+ };++ const handleSocialSignIn = async (+ provider: "google" | "github" | "twitter"+ ) => {+ try {+ await authClient.signIn.social({+ provider,+ });+ } catch (error) {+ setError(String(error));+ }+ };++ return (+ <form onSubmit={handleLogin}>+ <div className="flex flex-col gap-4">+ <div className="grid gap-2">+ <Label htmlFor="email">Email</Label>+ <Input+ id="email"+ type="email"+ placeholder="[email protected]"+ required+ value={email}+ onChange={(e) => setEmail(e.target.value)}+ />+ </div>+ <div className="grid gap-2">+ <Label htmlFor="password">Password</Label>+ <Input+ id="password"+ type="password"+ required+ value={password}+ onChange={(e) => setPassword(e.target.value)}+ placeholder="••••••••"+ />+ </div>+ <Button+ type="submit"+ className="w-full"+ disabled={isLoading}+ variant="success"+ >+ {isLoading ? "Logging in..." : "Login to Accept Invitation"}+ </Button>++ {IS_CLOUD && (+ <>+ <div className="relative flex justify-center text-xs uppercase">+ <span className="bg-background px-2 text-muted-foreground">+ Or continue with+ </span>+ </div>++ <div className="flex flex-col gap-2">+ <Button+ type="button"+ variant="outline"+ onClick={() => handleSocialSignIn("google")}+ >+ <GoogleLogo weight="bold" className="mr-2" />+ </Button>+ <Button+ type="button"+ variant="outline"+ onClick={() => handleSocialSignIn("github")}+ >+ <GithubLogo weight="bold" className="mr-2" />+ GitHub+ </Button>+ </div>+ </>+ )}++ {error && (+ <Alert variant="destructive">+ <AlertCircle className="h-4 w-4" />+ <AlertTitle>Error</AlertTitle>+ <AlertDescription>{error}</AlertDescription>+ </Alert>+ )}+ </div>+ </form>+ );+}diff --git a/client/src/app/invitation/components/signup.tsx b/client/src/app/invitation/components/signup.tsxnew file mode 100644index 000000000..16422bb0a--- /dev/null+++ b/client/src/app/invitation/components/signup.tsx@@ -0,0 +1,155 @@+"use client";++import { GithubLogo, GoogleLogo } from "@phosphor-icons/react/dist/ssr";+import { AlertCircle } from "lucide-react";+import { useState } from "react";+import {+ Alert,+ AlertDescription,+ AlertTitle,+} from "../../../components/ui/alert";+import { Button } from "../../../components/ui/button";+import { Input } from "../../../components/ui/input";+import { Label } from "../../../components/ui/label";+import { authClient } from "../../../lib/auth";+import { IS_CLOUD } from "../../../lib/const";+import { userStore } from "../../../lib/userStore";++interface SignupProps {+ inviterEmail?: string | null;+ organization?: string | null;+}++export function Signup({ inviterEmail, organization }: SignupProps) {+ const [isLoading, setIsLoading] = useState(false);+ const [error, setError] = useState<string>("");+ const [name, setName] = useState("");+ const [email, setEmail] = useState("");+ const [password, setPassword] = useState("");++ const handleSignup = async (e: React.FormEvent) => {+ e.preventDefault();+ setIsLoading(true);+ setError("");++ try {+ const { data, error } = await authClient.signUp.email({+ email,+ name,+ password,+ });++ if (data?.user) {+ userStore.setState({+ user: data.user,+ });+ // Force reload to show the AcceptInvitationInner component+ window.location.reload();+ }++ if (error) {+ setError(error.message || "An error occurred during signup");+ }+ } catch (error) {+ setError(String(error));+ } finally {+ setIsLoading(false);+ }+ };++ const handleSocialSignIn = async (+ provider: "google" | "github" | "twitter"+ ) => {+ try {+ await authClient.signIn.social({+ provider,+ });+ } catch (error) {+ setError(String(error));+ }+ };++ return (+ <form onSubmit={handleSignup}>+ <div className="flex flex-col gap-4">+ <div className="grid gap-2">+ <Label htmlFor="name">Name</Label>+ <Input+ id="name"+ type="text"+ placeholder="Your name"+ value={name}+ onChange={(e) => setName(e.target.value)}+ />+ </div>+ <div className="grid gap-2">+ <Label htmlFor="email">Email</Label>+ <Input+ id="email"+ type="email"+ placeholder="[email protected]"+ required+ value={email}+ onChange={(e) => setEmail(e.target.value)}+ />+ </div>+ <div className="grid gap-2">+ <Label htmlFor="password">Password</Label>+ <Input+ id="password"+ type="password"+ placeholder="••••••••"+ required+ value={password}+ onChange={(e) => setPassword(e.target.value)}+ />+ </div>+ <Button+ type="submit"+ className="w-full"+ disabled={isLoading}+ variant="success"+ >+ {isLoading ? "Creating account..." : "Sign Up to Accept Invitation"}+ </Button>++ {IS_CLOUD && (+ <>+ <div className="relative flex justify-center text-xs uppercase">+ <span className="bg-background px-2 text-muted-foreground">+ Or continue with+ </span>+ </div>++ <div className="flex flex-col gap-2">+ <Button+ type="button"+ variant="outline"+ onClick={() => handleSocialSignIn("google")}+ >+ <GoogleLogo weight="bold" className="mr-2" />+ </Button>+ <Button+ type="button"+ variant="outline"+ onClick={() => handleSocialSignIn("github")}+ >+ <GithubLogo weight="bold" className="mr-2" />+ GitHub+ </Button>+ </div>+ </>+ )}++ {error && (+ <Alert variant="destructive">+ <AlertCircle className="h-4 w-4" />+ <AlertTitle>Error</AlertTitle>+ <AlertDescription>{error}</AlertDescription>+ </Alert>+ )}+ </div>+ </form>+ );+}diff --git a/client/src/app/invitation/page.tsx b/client/src/app/invitation/page.tsxnew file mode 100644index 000000000..cb4b7a792--- /dev/null+++ b/client/src/app/invitation/page.tsx@@ -0,0 +1,150 @@+"use client";++import { AlertCircle } from "lucide-react";+import Image from "next/image";+import { useRouter, useSearchParams } from "next/navigation";+import { useState } from "react";+import { ThreeDotLoader } from "../../components/Loaders";+import { TopBar } from "../../components/TopBar";+import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";+import { Button } from "../../components/ui/button";+import {+ Card,+ CardContent,+ CardHeader,+ CardTitle,+} from "../../components/ui/card";+import {+ Tabs,+ TabsContent,+ TabsList,+ TabsTrigger,+} from "../../components/ui/tabs";+import { authClient } from "../../lib/auth";+import { Login } from "./components/login";+import { Signup } from "./components/signup";++function AuthComponent() {+ const organization = useSearchParams().get("organization");+ const inviterEmail = useSearchParams().get("inviterEmail");+ const [activeTab, setActiveTab] = useState<"login" | "signup">("signup");++ return (+ <Card className="w-full max-w-md p-1">+ <CardHeader>+ <Image src="/rybbit.png" alt="Rybbit" width={32} height={32} />+ <CardTitle className="text-2xl flex justify-center">+ Join {organization}+ </CardTitle>+ <p className="text-center text-sm text-muted-foreground mt-2">+ You've been invited by {inviterEmail}+ </p>+ </CardHeader>+ <CardContent>+ <Tabs+ defaultValue="login"+ value={activeTab}+ onValueChange={(v) => setActiveTab(v as "login" | "signup")}+ >+ <TabsList className="grid w-full grid-cols-2 mb-6">+ <TabsTrigger value="signup">Sign Up</TabsTrigger>+ <TabsTrigger value="login">Login</TabsTrigger>+ </TabsList>++ <TabsContent value="login">+ <Login inviterEmail={inviterEmail} organization={organization} />+ </TabsContent>++ <TabsContent value="signup">+ <Signup inviterEmail={inviterEmail} organization={organization} />+ </TabsContent>+ </Tabs>+ </CardContent>+ </Card>+ );+}++function AcceptInvitationInner() {+ const invitationId = useSearchParams().get("invitationId");+ const organization = useSearchParams().get("organization");+ const inviterEmail = useSearchParams().get("inviterEmail");+ const router = useRouter();+ const [isLoading, setIsLoading] = useState(false);+ const [error, setError] = useState<string>("");++ const acceptInvitation = async () => {+ setIsLoading(true);+ setError("");+ try {+ const res = await authClient.organization.acceptInvitation({+ invitationId: invitationId ?? "",+ });+ if (res.error) {+ setError(res.error.message ?? "");+ } else {+ router.push("/");+ }+ } catch (error) {+ setError(String(error));+ } finally {+ setIsLoading(false);+ }+ };++ return (+ <Card className="w-full max-w-md">+ <CardHeader>+ <Image src="/rybbit.png" alt="Rybbit" width={32} height={32} />+ <CardTitle className="text-2xl flex justify-center">+ Invitation+ </CardTitle>+ </CardHeader>+ <CardContent>+ <div className="flex flex-col gap-4">+ <p className="text-center">+ You have been invited to join{" "}+ <span className="font-bold">{organization}</span> by{" "}+ <span className="font-bold">{inviterEmail}</span>+ </p>++ <Button+ onClick={acceptInvitation}+ disabled={isLoading}+ variant="success"+ className="w-full"+ >+ {isLoading ? "Accepting..." : "Accept Invitation"}+ </Button>++ {error && (+ <Alert variant="destructive">+ <AlertCircle className="h-4 w-4" />+ <AlertTitle>Error</AlertTitle>+ <AlertDescription>{error}</AlertDescription>+ </Alert>+ )}+ </div>+ </CardContent>+ </Card>+ );+}++export default function AcceptInvitation() {+ const { data: sessionData, isPending } = authClient.useSession();++ return (+ <div className="flex flex-col min-h-screen">+ <TopBar />++ <div className="flex justify-center items-center flex-grow p-4">+ {isPending ? (+ <ThreeDotLoader />+ ) : !sessionData?.user ? (+ <AuthComponent />+ ) : (+ <AcceptInvitationInner />+ )}+ </div>+ </div>+ );+}diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsxindex c9c791cd8..1267f2263 100644--- a/client/src/app/layout.tsx+++ b/client/src/app/layout.tsx@@ -14,7 +14,7 @@ import Script from "next/script";const inter = Inter({ subsets: ["latin"] });-const publicRoutes = ["/login", "/signup"];+const publicRoutes = ["/login", "/signup", "/invitation"];// Helper function to check if a site is publicasync function checkIfSiteIsPublic(siteId: string): Promise<boolean> {@@ -50,7 +50,9 @@ export default function RootLayout({// Don't check for public site status on obvious non-site pathsif (!publicRoutes.includes(`/${potentialSiteId}`) &&- !["_next", "api", "settings", "subscribe"].includes(potentialSiteId)+ !["_next", "api", "settings", "subscribe", "invitation"].includes(+ potentialSiteId+ )) {setIsCheckingPublic(true);diff --git a/client/src/app/settings/organizations/components/AddMemberDialog.tsx b/client/src/app/settings/organizations/components/AddMemberDialog.tsxdeleted file mode 100644index 9f46fa4ca..000000000--- a/client/src/app/settings/organizations/components/AddMemberDialog.tsx+++ /dev/null@@ -1,131 +0,0 @@-"use client";--import { Button } from "@/components/ui/button";-import {- Dialog,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/components/ui/dialog";-import { Input } from "@/components/ui/input";-import { Label } from "@/components/ui/label";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@/components/ui/select";-import { UserPlus } from "lucide-react";-import { useState } from "react";-import { toast } from "sonner";-import { Alert } from "../../../../components/ui/alert";-import { BACKEND_URL } from "../../../../lib/const";--interface AddMemberDialogProps {- organizationId: string;- onSuccess: () => void;-}--export function AddMemberDialog({- organizationId,- onSuccess,-}: AddMemberDialogProps) {- const [email, setEmail] = useState("");- const [role, setRole] = useState("admin");-- const [isLoading, setIsLoading] = useState(false);- const [open, setOpen] = useState(false);- const [error, setError] = useState("");-- const handleInvite = async () => {- if (!email) {- setError("Email is required");- return;- }-- setIsLoading(true);- try {- await fetch(`${BACKEND_URL}/add-user-to-organization`, {- method: "POST",- body: JSON.stringify({- email: email,- role: role,- organizationId: organizationId,- }),- headers: {- "Content-Type": "application/json",- },- credentials: "include",- });-- toast.success(`Invitation sent to ${email}`);- setOpen(false);- onSuccess();- setEmail("");- setRole("member");- } catch (error: any) {- setError(error.message || "Failed to send invitation");- } finally {- setIsLoading(false);- }- };-- return (- <Dialog open={open} onOpenChange={setOpen}>- <DialogTrigger asChild>- <Button size="sm" variant="outline">- <UserPlus className="h-4 w-4 mr-1" />- Add Member- </Button>- </DialogTrigger>- <DialogContent className="max-w-lg">- <DialogHeader>- <DialogTitle>Add a new member</DialogTitle>- <DialogDescription>- Add a new member to this organization.- </DialogDescription>- </DialogHeader>- <div className="grid gap-4 py-4">- <div className="grid gap-2">- <Label htmlFor="email">Email</Label>- <Input- id="email"- type="email"- placeholder="[email protected]"- value={email}- onChange={(e: React.ChangeEvent<HTMLInputElement>) =>- setEmail(e.target.value)- }- />- </div>- <div className="grid gap-2">- <Label htmlFor="role">Role</Label>- <Select value={role} onValueChange={setRole}>- <SelectTrigger>- <SelectValue placeholder="Select a role" />- </SelectTrigger>- <SelectContent>- {/* <SelectItem value="owner">Owner</SelectItem> */}- <SelectItem value="admin">Admin</SelectItem>- <SelectItem value="member">Member</SelectItem>- </SelectContent>- </Select>- </div>- {error && <Alert variant="destructive">{error}</Alert>}- </div>- <DialogFooter>- <Button variant="outline" onClick={() => setOpen(false)}>- Cancel- </Button>- <Button onClick={handleInvite} disabled={isLoading} variant="success">- {isLoading ? "Adding..." : "Add"}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>- );-}diff --git a/client/src/app/settings/organizations/components/Invitations.tsx b/client/src/app/settings/organizations/components/Invitations.tsxnew file mode 100644index 000000000..2556fbb7d--- /dev/null+++ b/client/src/app/settings/organizations/components/Invitations.tsx@@ -0,0 +1,166 @@+"use client";+import { DateTime } from "luxon";+import { useQuery } from "@tanstack/react-query";+import { authClient } from "../../../../lib/auth";+import {+ Card,+ CardContent,+ CardHeader,+ CardTitle,+} from "../../../../components/ui/card";+import {+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+} from "../../../../components/ui/table";+import { Badge } from "../../../../components/ui/badge";+import { Button } from "../../../../components/ui/button";+import { useState } from "react";+import { toast } from "sonner";+import { useOrganizationInvitations } from "../../../../api/admin/organizations";++interface InvitationsProps {+ organizationId: string;+ isOwner: boolean;+}++export function Invitations({ organizationId, isOwner }: InvitationsProps) {+ const [loadingInvitationId, setLoadingInvitationId] = useState<string | null>(+ null+ );++ const { data: invitations, refetch: refetchInvitations } =+ useOrganizationInvitations(organizationId);++ const handleCancelInvitation = async (invitationId: string) => {+ try {+ setLoadingInvitationId(invitationId);+ await authClient.organization.cancelInvitation({+ invitationId,+ });+ toast.success("Invitation cancelled");+ refetchInvitations();+ } catch (error: any) {+ toast.error(error.message || "Failed to cancel invitation");+ } finally {+ setLoadingInvitationId(null);+ }+ };++ const handleResendInvitation = async (invitation: any) => {+ try {+ setLoadingInvitationId(invitation.id);+ await authClient.organization.inviteMember({+ email: invitation.email,+ role: invitation.role,+ organizationId,+ resend: true,+ });+ toast.success(`Invitation resent to ${invitation.email}`);+ refetchInvitations();+ } catch (error: any) {+ toast.error(error.message || "Failed to resend invitation");+ } finally {+ setLoadingInvitationId(null);+ }+ };++ // Helper function to determine badge variant+ const getBadgeVariant = (status: string) => {+ switch (status) {+ case "pending":+ return "secondary";+ case "accepted":+ return "green";+ case "rejected":+ return "destructive";+ case "canceled":+ return "warning";+ default:+ return "outline";+ }+ };++ return (+ <Card className="w-full">+ <CardHeader className="pb-2">+ <CardTitle className="text-xl">Invitations</CardTitle>+ </CardHeader>+ <CardContent>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Email</TableHead>+ <TableHead>Role</TableHead>+ <TableHead>Status</TableHead>+ <TableHead>Expires</TableHead>+ {isOwner && <TableHead className="w-12">Actions</TableHead>}+ </TableRow>+ </TableHeader>+ <TableBody>+ {invitations?.length && invitations.length > 0 ? (+ invitations.map((invitation) => (+ <TableRow key={invitation.id}>+ <TableCell>{invitation.email}</TableCell>+ <TableCell className="capitalize">+ {invitation.role}+ </TableCell>+ <TableCell>+ <Badge variant={getBadgeVariant(invitation.status)}>+ {invitation.status}+ </Badge>+ </TableCell>+ <TableCell>+ {DateTime.fromJSDate(+ new Date(invitation.expiresAt)+ ).toLocaleString(DateTime.DATE_SHORT)}+ </TableCell>+ {isOwner && (+ <TableCell className="text-right">+ {invitation.status === "pending" && (+ <Button+ variant="default"+ size="sm"+ disabled={loadingInvitationId === invitation.id}+ onClick={() => handleCancelInvitation(invitation.id)}+ >+ {loadingInvitationId === invitation.id+ ? "Processing..."+ : "Cancel"}+ </Button>+ )}+ {invitation.status === "canceled" && (+ <Button+ variant="default"+ size="sm"+ disabled={loadingInvitationId === invitation.id}+ onClick={() => handleResendInvitation(invitation)}+ >+ {loadingInvitationId === invitation.id+ ? "Processing..."+ : "Resend"}+ </Button>+ )}+ </TableCell>+ )}+ </TableRow>+ ))+ ) : (+ <TableRow>+ <TableCell+ colSpan={isOwner ? 5 : 4}+ className="text-center py-6 text-muted-foreground"+ >+ No pending invitations+ </TableCell>+ </TableRow>+ )}+ </TableBody>+ </Table>+ </CardContent>+ </Card>+ );+}diff --git a/client/src/app/settings/organizations/components/InviteMemberDialog.tsx b/client/src/app/settings/organizations/components/InviteMemberDialog.tsxindex db65c04fe..7dc1a9068 100644--- a/client/src/app/settings/organizations/components/InviteMemberDialog.tsx+++ b/client/src/app/settings/organizations/components/InviteMemberDialog.tsx@@ -1,24 +1,29 @@"use client";-import { useState } from "react";import { Button } from "@/components/ui/button";-import { Dialog } from "@/components/ui/dialog";-import { DialogContent } from "@/components/ui/dialog";-import { DialogHeader } from "@/components/ui/dialog";-import { DialogTitle } from "@/components/ui/dialog";-import { DialogTrigger } from "@/components/ui/dialog";-import { DialogFooter } from "@/components/ui/dialog";-import { DialogDescription } from "@/components/ui/dialog";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/components/ui/dialog";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";-import { Select } from "@/components/ui/select";-import { SelectContent } from "@/components/ui/select";-import { SelectItem } from "@/components/ui/select";-import { SelectTrigger } from "@/components/ui/select";-import { SelectValue } from "@/components/ui/select";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";import { UserPlus } from "lucide-react";-import { authClient } from "@/lib/auth";+import { useState } from "react";import { toast } from "sonner";+import { Alert } from "../../../../components/ui/alert";+import { authClient } from "../../../../lib/auth";interface InviteMemberDialogProps {organizationId: string;@@ -30,22 +35,38 @@ export function InviteMemberDialog({onSuccess,}: InviteMemberDialogProps) {const [email, setEmail] = useState("");- const [role, setRole] = useState("member");+ const [role, setRole] = useState<"admin" | "member">("member");+const [isLoading, setIsLoading] = useState(false);const [open, setOpen] = useState(false);+ const [error, setError] = useState("");const handleInvite = async () => {if (!email) {- toast.error("Email is required");+ setError("Email is required");return;}setIsLoading(true);try {+ // await fetch(`${BACKEND_URL}/add-user-to-organization`, {+ // method: "POST",+ // body: JSON.stringify({+ // email: email,+ // role: role,+ // organizationId: organizationId,+ // }),+ // headers: {+ // "Content-Type": "application/json",+ // },+ // credentials: "include",+ // });+await authClient.organization.inviteMember({email,- role: role as "admin" | "member" | "owner",+ role,organizationId,+ resend: true,});toast.success(`Invitation sent to ${email}`);@@ -54,7 +75,7 @@ export function InviteMemberDialog({setEmail("");setRole("member");} catch (error: any) {- toast.error(error.message || "Failed to send invitation");+ setError(error.message || "Failed to send invitation");} finally {setIsLoading(false);}@@ -63,7 +84,7 @@ export function InviteMemberDialog({return (<Dialog open={open} onOpenChange={setOpen}><DialogTrigger asChild>- <Button size="sm" variant="outline" className="ml-2">+ <Button size="sm" variant="outline"><UserPlus className="h-4 w-4 mr-1" />Invite Member</Button>@@ -72,7 +93,7 @@ export function InviteMemberDialog({<DialogHeader><DialogTitle>Invite a new member</DialogTitle><DialogDescription>- Send an invitation to add someone to this organization.+ Invite a new member to this organization.</DialogDescription></DialogHeader><div className="grid gap-4 py-4">@@ -90,24 +111,28 @@ export function InviteMemberDialog({</div><div className="grid gap-2"><Label htmlFor="role">Role</Label>- <Select value={role} onValueChange={setRole}>+ <Select+ value={role}+ onValueChange={(value) => setRole(value as "admin" | "member")}+ ><SelectTrigger><SelectValue placeholder="Select a role" /></SelectTrigger><SelectContent>- <SelectItem value="member">Member</SelectItem>+ {/* <SelectItem value="owner">Owner</SelectItem> */}<SelectItem value="admin">Admin</SelectItem>- <SelectItem value="owner">Owner</SelectItem>+ <SelectItem value="member">Member</SelectItem></SelectContent></Select></div>+ {error && <Alert variant="destructive">{error}</Alert>}</div><DialogFooter><Button variant="outline" onClick={() => setOpen(false)}>Cancel</Button><Button onClick={handleInvite} disabled={isLoading} variant="success">- {isLoading ? "Sending..." : "Send Invitation"}+ {isLoading ? "Inviting..." : "Invite"}</Button></DialogFooter></DialogContent>diff --git a/client/src/app/settings/organizations/components/RemoveMemberDialog.tsx b/client/src/app/settings/organizations/components/RemoveMemberDialog.tsxindex 4e577186f..75e4cc191 100644--- a/client/src/app/settings/organizations/components/RemoveMemberDialog.tsx+++ b/client/src/app/settings/organizations/components/RemoveMemberDialog.tsx@@ -58,16 +58,10 @@ export function RemoveMemberDialog({<DialogHeader><DialogTitle>Remove Member</DialogTitle><DialogDescription>- Are you sure you want to remove this member from the organization?+ Are you sure you want to remove {member.user.name} from the+ organization?</DialogDescription></DialogHeader>- <div className="py-4">- <p>- You are about to remove{" "}- <strong>{member.user.name || member.user.email}</strong> from this- organization.- </p>- </div><DialogFooter><Button variant="outline" onClick={() => setOpen(false)}>Canceldiff --git a/client/src/app/settings/organizations/page.tsx b/client/src/app/settings/organizations/page.tsxindex 7d761e1dd..e979ae8f7 100644--- a/client/src/app/settings/organizations/page.tsx+++ b/client/src/app/settings/organizations/page.tsx@@ -19,15 +19,17 @@ import { authClient } from "../../../lib/auth";// Import the separated dialog componentsimport { useOrganizationMembers } from "../../../api/admin/auth";import {+ useOrganizationInvitations,UserOrganization,useUserOrganizations,} from "../../../api/admin/organizations";import { NoOrganization } from "../../../components/NoOrganization";-import { AddMemberDialog } from "./components/AddMemberDialog";+import { InviteMemberDialog } from "./components/InviteMemberDialog";import { DeleteOrganizationDialog } from "./components/DeleteOrganizationDialog";import { EditOrganizationDialog } from "./components/EditOrganizationDialog";import { RemoveMemberDialog } from "./components/RemoveMemberDialog";import { useSetPageTitle } from "../../../hooks/useSetPageTitle";+import { Invitations } from "./components/Invitations";// Types for our componentexport type Organization = {@@ -54,24 +56,7 @@ export type Member = {// Organization Component with Members Tablefunction Organization({ org }: { org: UserOrganization }) {const { data: members, refetch } = useOrganizationMembers(org.id);-- // const { data: invitations, refetch: refetchInvitations } = useQuery({- // queryKey: ["invitations", org.id],- // queryFn: async () => {- // const invitations = await authClient.organization.listInvitations({- // query: {- // organizationId: org.id,- // },- // });-- // if (invitations.error) {- // throw new Error(invitations.error.message);- // }-- // return invitations.data;- // },- // });-+ const { refetch: refetchInvitations } = useOrganizationInvitations(org.id);const { data } = authClient.useSession();const isOwner = members?.data.find(@@ -80,7 +65,7 @@ function Organization({ org }: { org: UserOrganization }) {const handleRefresh = () => {refetch();- // refetchInvitations();+ refetchInvitations();};return (@@ -98,7 +83,7 @@ function Organization({ org }: { org: UserOrganization }) {<div className="flex items-center gap-2">{isOwner && (<>- <AddMemberDialog+ <InviteMemberDialogorganizationId={org.id}onSuccess={handleRefresh}/>@@ -164,81 +149,8 @@ function Organization({ org }: { org: UserOrganization }) {</Table></CardContent></Card>- {/* Disabled for now. We aren't using this */}- {/*- <Card className="w-full">- <CardHeader className="pb-2">- <CardTitle className="text-xl">Pending Invitations</CardTitle>- </CardHeader>- <CardContent>- <Table>- <TableHeader>- <TableRow>- <TableHead>Email</TableHead>- <TableHead>Role</TableHead>- <TableHead>Status</TableHead>- <TableHead>Expires</TableHead>- {isOwner && <TableHead className="w-12">Actions</TableHead>}- </TableRow>- </TableHeader>- <TableBody>- {invitations?.length && invitations.length > 0 ? (- invitations.map((invitation) => (- <TableRow key={invitation.id}>- <TableCell>{invitation.email}</TableCell>- <TableCell className="capitalize">- {invitation.role}- </TableCell>- <TableCell>- <Badge- variant={- invitation.status === "pending"- ? "outline"- : invitation.status === "accepted"- ? "default"- : "destructive"- }- >- {invitation.status}- </Badge>- </TableCell>- <TableCell>- {DateTime.fromJSDate(- new Date(invitation.expiresAt)- ).toLocaleString(DateTime.DATE_SHORT)}- </TableCell>- {isOwner && (- <TableCell className="text-right">- <Button- variant="outline"- size="sm"- onClick={async () => {- await authClient.organization.cancelInvitation({- invitationId: invitation.id,- });- refetchInvitations();- }}- >- Cancel- </Button>- </TableCell>- )}- </TableRow>- ))- ) : (- <TableRow>- <TableCell- colSpan={isOwner ? 5 : 4}- className="text-center py-6 text-muted-foreground"- >- No pending invitations- </TableCell>- </TableRow>- )}- </TableBody>- </Table>- </CardContent>- </Card> */}++ <Invitations organizationId={org.id} isOwner={!!isOwner} /></>);}diff --git a/client/src/components/Sessions/SessionCard.tsx b/client/src/components/Sessions/SessionCard.tsxindex d9daac9a7..c152187f6 100644--- a/client/src/components/Sessions/SessionCard.tsx+++ b/client/src/components/Sessions/SessionCard.tsx@@ -11,7 +11,7 @@ import {FileText,Laptop,MousePointerClick,- Smartphone+ Smartphone,} from "lucide-react";import { DateTime, Duration } from "luxon";import { memo, useState } from "react";@@ -192,10 +192,10 @@ export function SessionCard({ session, onClick, userId }: SessionCardProps) {<span className="text-gray-400">{DateTime.fromSQL(session.session_start, {zone: "utc",- }).setLocale(userLocale)+ })+ .setLocale(userLocale).toLocal()- .toFormat(hour12 ? "MMM d, h:mm a" : "dd MMM, HH:mm")- }+ .toFormat(hour12 ? "MMM d, h:mm a" : "dd MMM, HH:mm")}</span><span className="hidden md:block">{duration}</span></div>@@ -286,7 +286,9 @@ export const SessionCardSkeleton = memo(() => {<Skeleton className={cn("h-3", getRandomTimeWidth())} />{/* Duration skeleton */}- <Skeleton className={cn("h-3", getRandomDurationWidth(), "hidden md:block")} />+ <Skeleton+ className={cn("h-3", getRandomDurationWidth(), "hidden md:block")}+ /></div>{/* Expand icon */}diff --git a/client/src/components/ui/badge.tsx b/client/src/components/ui/badge.tsxindex dfa32c0c4..a09964691 100644--- a/client/src/components/ui/badge.tsx+++ b/client/src/components/ui/badge.tsx@@ -14,6 +14,8 @@ const badgeVariants = cva("border-transparent bg-neutral-100 text-neutral-900 hover:bg-neutral-100/80 dark:bg-neutral-800 dark:text-neutral-50 dark:hover:bg-neutral-800/80",destructive:"border-transparent bg-red-500 text-neutral-50 shadow hover:bg-red-500/80 dark:bg-red-900 dark:text-neutral-50 dark:hover:bg-red-900/80",+ warning:+ "border-transparent bg-yellow-500 text-neutral-50 shadow hover:bg-yellow-500/80 dark:bg-yellow-800 dark:text-neutral-50 dark:hover:bg-yellow-800/80",outline: "text-neutral-950 dark:text-neutral-50",green:"border-transparent bg-green-500 text-green-200 shadow hover:bg-green-500/80 dark:bg-green-900 dark:text-green-300 dark:hover:bg-green-900/80",diff --git a/client/src/components/ui/button.tsx b/client/src/components/ui/button.tsxindex f4b6f3196..8b5b3064c 100644--- a/client/src/components/ui/button.tsx+++ b/client/src/components/ui/button.tsx@@ -20,7 +20,7 @@ const buttonVariants = cva(destructive:"bg-red-500 text-neutral-50 border border-red-500 shadow-sm hover:bg-red-500/90 dark:bg-red-900 dark:border-red-700 dark:text-neutral-50 dark:hover:bg-red-900/90 dark:hover:border-red-500",warning:- "bg-yellow-500 text-neutral-900 border border-yellow-500 shadow-sm hover:bg-yellow-500/90 dark:bg-yellow-600 dark:border-yellow-500 dark:text-neutral-50 dark:hover:bg-yellow-600/90 dark:hover:border-yellow-400",+ "bg-yellow-500 text-neutral-900 border border-yellow-500 shadow-sm hover:bg-yellow-500/90 dark:bg-yellow-700 dark:border-yellow-500 dark:text-neutral-50 dark:hover:bg-yellow-700/90 dark:hover:border-yellow-400",outline:"border border-neutral-200 shadow-sm hover:bg-neutral-100 hover:text-neutral-900 dark:border-neutral-700 dark:hover:bg-neutral-900 dark:hover:border-neutral-600 dark:hover:text-neutral-50",ghost:diff --git a/client/src/middleware.ts b/client/src/middleware.tsindex caed56049..81c257585 100644--- a/client/src/middleware.ts+++ b/client/src/middleware.ts@@ -35,6 +35,7 @@ export async function middleware(request: NextRequest) {"signup","settings","subscribe",+ "invitation","auth","_next","api",diff --git a/docker-compose.cloud.yml b/docker-compose.cloud.ymlindex b67a803e1..2247f5038 100644--- a/docker-compose.cloud.yml+++ b/docker-compose.cloud.yml@@ -33,7 +33,15 @@ services:- CLICKHOUSE_USER=${CLICKHOUSE_USER:-default}- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog}healthcheck:- test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"]+ test:+ [+ "CMD",+ "wget",+ "--no-verbose",+ "--tries=1",+ "--spider",+ "http://localhost:8123/ping",+ ]interval: 3stimeout: 5sretries: 5@@ -79,6 +87,7 @@ services:- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}+ - RESEND_API_KEY=${RESEND_API_KEY}depends_on:clickhouse:condition: service_healthy@@ -111,5 +120,5 @@ services:volumes:clickhouse-data:postgres-data:- caddy_data: # Persistent volume for Caddy's certificates and state- caddy_config: # Persistent volume for Caddy's configuration cache (optional but good practice)+ caddy_data: # Persistent volume for Caddy's certificates and state+ caddy_config: # Persistent volume for Caddy's configuration cache (optional but good practice)diff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex dfd5a0239..5e87c689a 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -33,7 +33,15 @@ services:- CLICKHOUSE_USER=${CLICKHOUSE_USER:-default}- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog}healthcheck:- test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"]+ test:+ [+ "CMD",+ "wget",+ "--no-verbose",+ "--tries=1",+ "--spider",+ "http://localhost:8123/ping",+ ]interval: 3stimeout: 5sretries: 5@@ -79,6 +87,7 @@ services:- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}+ - RESEND_API_KEY=${RESEND_API_KEY}depends_on:clickhouse:condition: service_healthy@@ -112,5 +121,5 @@ services:volumes:clickhouse-data:postgres-data:- caddy_data: # Persistent volume for Caddy's certificates and state- caddy_config: # Persistent volume for Caddy's configuration cache (optional but good practice)+ caddy_data: # Persistent volume for Caddy's certificates and state+ caddy_config: # Persistent volume for Caddy's configuration cache (optional but good practice)diff --git a/docker-compose.yml b/docker-compose.ymlindex 42007ee71..d1d4029da 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -33,7 +33,15 @@ services:- CLICKHOUSE_USER=${CLICKHOUSE_USER:-default}- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog}healthcheck:- test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"]+ test:+ [+ "CMD",+ "wget",+ "--no-verbose",+ "--tries=1",+ "--spider",+ "http://localhost:8123/ping",+ ]interval: 3stimeout: 5sretries: 5@@ -72,6 +80,7 @@ services:- BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}- BASE_URL=${BASE_URL}- DISABLE_SIGNUP=${DISABLE_SIGNUP}+ - RESEND_API_KEY=${RESEND_API_KEY}depends_on:clickhouse:condition: service_healthy@@ -101,5 +110,5 @@ services:volumes:clickhouse-data:postgres-data:- caddy_data: # Persistent volume for Caddy's certificates and state- caddy_config: # Persistent volume for Caddy's configuration cache (optional but good practice)+ caddy_data: # Persistent volume for Caddy's certificates and state+ caddy_config: # Persistent volume for Caddy's configuration cache (optional but good practice)diff --git a/server/package-lock.json b/server/package-lock.jsonindex 080a20659..7bd2294ed 100644--- a/server/package-lock.json+++ b/server/package-lock.json@@ -24,6 +24,7 @@"node-cron": "4.0.5","pg": "8.16.0","postgres": "3.4.5",+ "resend": "^4.5.1","sqlstring": "2.3.3","stripe": "18.1.0","ua-parser-js": "2.0.3",@@ -1312,6 +1313,35 @@"tslib": "^2.8.1"}},+ "node_modules/@react-email/render": {+ "version": "1.0.6",+ "resolved": "https://registry.npmjs.org/@react-email/render/-/render-1.0.6.tgz",+ "integrity": "sha512-zNueW5Wn/4jNC1c5LFgXzbUdv5Lhms+FWjOvWAhal7gx5YVf0q6dPJ0dnR70+ifo59gcMLwCZEaTS9EEuUhKvQ==",+ "dependencies": {+ "html-to-text": "9.0.5",+ "prettier": "3.5.3",+ "react-promise-suspense": "0.3.4"+ },+ "engines": {+ "node": ">=18.0.0"+ },+ "peerDependencies": {+ "react": "^18.0 || ^19.0 || ^19.0.0-rc",+ "react-dom": "^18.0 || ^19.0 || ^19.0.0-rc"+ }+ },+ "node_modules/@selderee/plugin-htmlparser2": {+ "version": "0.11.0",+ "resolved": "https://registry.npmjs.org/@selderee/plugin-htmlparser2/-/plugin-htmlparser2-0.11.0.tgz",+ "integrity": "sha512-P33hHGdldxGabLFjPPpaTxVolMrzrcegejx+0GxjrIb9Zv48D8yAIA/QTDR2dFl7Uz7urX8aX6+5bCZslr+gWQ==",+ "dependencies": {+ "domhandler": "^5.0.3",+ "selderee": "^0.11.0"+ },+ "funding": {+ "url": "https://ko-fi.com/killymxi"+ }+ },"node_modules/@simplewebauthn/browser": {"version": "13.1.0","resolved": "https://registry.npmjs.org/@simplewebauthn/browser/-/browser-13.1.0.tgz",@@ -1816,6 +1846,14 @@}}},+ "node_modules/deepmerge": {+ "version": "4.3.1",+ "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",+ "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==",+ "engines": {+ "node": ">=0.10.0"+ }+ },"node_modules/defu": {"version": "6.1.4","resolved": "https://registry.npmjs.org/defu/-/defu-6.1.4.tgz",@@ -1879,6 +1917,57 @@"node": ">=0.3.1"}},+ "node_modules/dom-serializer": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",+ "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==",+ "dependencies": {+ "domelementtype": "^2.3.0",+ "domhandler": "^5.0.2",+ "entities": "^4.2.0"+ },+ "funding": {+ "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1"+ }+ },+ "node_modules/domelementtype": {+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz",+ "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==",+ "funding": [+ {+ "type": "github",+ "url": "https://github.com/sponsors/fb55"+ }+ ]+ },+ "node_modules/domhandler": {+ "version": "5.0.3",+ "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",+ "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",+ "dependencies": {+ "domelementtype": "^2.3.0"+ },+ "engines": {+ "node": ">= 4"+ },+ "funding": {+ "url": "https://github.com/fb55/domhandler?sponsor=1"+ }+ },+ "node_modules/domutils": {+ "version": "3.2.2",+ "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz",+ "integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==",+ "dependencies": {+ "dom-serializer": "^2.0.0",+ "domelementtype": "^2.3.0",+ "domhandler": "^5.0.3"+ },+ "funding": {+ "url": "https://github.com/fb55/domutils?sponsor=1"+ }+ },"node_modules/dotenv": {"version": "16.5.0","resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",@@ -2073,6 +2162,17 @@"once": "^1.4.0"}},+ "node_modules/entities": {+ "version": "4.5.0",+ "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",+ "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",+ "engines": {+ "node": ">=0.12"+ },+ "funding": {+ "url": "https://github.com/fb55/entities?sponsor=1"+ }+ },"node_modules/es-define-property": {"version": "1.0.1","resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",@@ -2556,6 +2656,39 @@"integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==","license": "MIT"},+ "node_modules/html-to-text": {+ "version": "9.0.5",+ "resolved": "https://registry.npmjs.org/html-to-text/-/html-to-text-9.0.5.tgz",+ "integrity": "sha512-qY60FjREgVZL03vJU6IfMV4GDjGBIoOyvuFdpBDIX9yTlDw0TjxVBQp+P8NvpdIXNJvfWBTNul7fsAQJq2FNpg==",+ "dependencies": {+ "@selderee/plugin-htmlparser2": "^0.11.0",+ "deepmerge": "^4.3.1",+ "dom-serializer": "^2.0.0",+ "htmlparser2": "^8.0.2",+ "selderee": "^0.11.0"+ },+ "engines": {+ "node": ">=14"+ }+ },+ "node_modules/htmlparser2": {+ "version": "8.0.2",+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz",+ "integrity": "sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==",+ "funding": [+ "https://github.com/fb55/htmlparser2?sponsor=1",+ {+ "type": "github",+ "url": "https://github.com/sponsors/fb55"+ }+ ],+ "dependencies": {+ "domelementtype": "^2.3.0",+ "domhandler": "^5.0.3",+ "domutils": "^3.0.1",+ "entities": "^4.4.0"+ }+ },"node_modules/http-errors": {"version": "2.0.0","resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",@@ -2771,6 +2904,14 @@"node": ">=14.0.0"}},+ "node_modules/leac": {+ "version": "0.6.0",+ "resolved": "https://registry.npmjs.org/leac/-/leac-0.6.0.tgz",+ "integrity": "sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg==",+ "funding": {+ "url": "https://ko-fi.com/killymxi"+ }+ },"node_modules/light-my-request": {"version": "6.6.0","resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-6.6.0.tgz",@@ -3049,6 +3190,18 @@"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==","license": "BlueOak-1.0.0"},+ "node_modules/parseley": {+ "version": "0.12.1",+ "resolved": "https://registry.npmjs.org/parseley/-/parseley-0.12.1.tgz",+ "integrity": "sha512-e6qHKe3a9HWr0oMRVDTRhKce+bRO8VGQR3NyVwcjwrbhMmFCX9KszEV35+rn4AdilFAq9VPxP/Fe1wC9Qjd2lw==",+ "dependencies": {+ "leac": "^0.6.0",+ "peberminta": "^0.9.0"+ },+ "funding": {+ "url": "https://ko-fi.com/killymxi"+ }+ },"node_modules/path-is-absolute": {"version": "1.0.1","resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",@@ -3091,6 +3244,14 @@"url": "https://github.com/sponsors/isaacs"}},+ "node_modules/peberminta": {+ "version": "0.9.0",+ "resolved": "https://registry.npmjs.org/peberminta/-/peberminta-0.9.0.tgz",+ "integrity": "sha512-XIxfHpEuSJbITd1H3EeQwpcZbTLHc+VVr8ANI9t5sit565tsI4/xK3KWTUFE2e6QiangUkh3B0jihzmGnNrRsQ==",+ "funding": {+ "url": "https://ko-fi.com/killymxi"+ }+ },"node_modules/pg": {"version": "8.16.0","resolved": "https://registry.npmjs.org/pg/-/pg-8.16.0.tgz",@@ -3407,6 +3568,20 @@"devOptional": true,"license": "MIT"},+ "node_modules/prettier": {+ "version": "3.5.3",+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz",+ "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==",+ "bin": {+ "prettier": "bin/prettier.cjs"+ },+ "engines": {+ "node": ">=14"+ },+ "funding": {+ "url": "https://github.com/prettier/prettier?sponsor=1"+ }+ },"node_modules/process-warning": {"version": "5.0.0","resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz",@@ -3472,6 +3647,40 @@"integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==","license": "MIT"},+ "node_modules/react": {+ "version": "19.1.0",+ "resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",+ "integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==",+ "peer": true,+ "engines": {+ "node": ">=0.10.0"+ }+ },+ "node_modules/react-dom": {+ "version": "19.1.0",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.1.0.tgz",+ "integrity": "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==",+ "peer": true,+ "dependencies": {+ "scheduler": "^0.26.0"+ },+ "peerDependencies": {+ "react": "^19.1.0"+ }+ },+ "node_modules/react-promise-suspense": {+ "version": "0.3.4",+ "resolved": "https://registry.npmjs.org/react-promise-suspense/-/react-promise-suspense-0.3.4.tgz",+ "integrity": "sha512-I42jl7L3Ze6kZaq+7zXWSunBa3b1on5yfvUW6Eo/3fFOj6dZ5Bqmcd264nJbTK/gn1HjjILAjSwnZbV4RpSaNQ==",+ "dependencies": {+ "fast-deep-equal": "^2.0.1"+ }+ },+ "node_modules/react-promise-suspense/node_modules/fast-deep-equal": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",+ "integrity": "sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w=="+ },"node_modules/readdirp": {"version": "3.6.0","resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",@@ -3503,6 +3712,17 @@"node": ">=0.10.0"}},+ "node_modules/resend": {+ "version": "4.5.1",+ "resolved": "https://registry.npmjs.org/resend/-/resend-4.5.1.tgz",+ "integrity": "sha512-ryhHpZqCBmuVyzM19IO8Egtc2hkWI4JOL5lf5F3P7Dydu3rFeX6lHNpGqG0tjWoZ63rw0l731JEmuJZBdDm3og==",+ "dependencies": {+ "@react-email/render": "1.0.6"+ },+ "engines": {+ "node": ">=18"+ }+ },"node_modules/resolve": {"version": "1.22.10","resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz",@@ -3673,6 +3893,12 @@"node": ">=10"}},+ "node_modules/scheduler": {+ "version": "0.26.0",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.26.0.tgz",+ "integrity": "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA==",+ "peer": true+ },"node_modules/secure-json-parse": {"version": "4.0.0","resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.0.0.tgz",@@ -3689,6 +3915,17 @@],"license": "BSD-3-Clause"},+ "node_modules/selderee": {+ "version": "0.11.0",+ "resolved": "https://registry.npmjs.org/selderee/-/selderee-0.11.0.tgz",+ "integrity": "sha512-5TF+l7p4+OsnP8BCCvSyZiSPc4x4//p5uPwK8TCnVPJYRmU2aYKMpOXvw8zM5a5JvuuCGN1jmsMwuU2W02ukfA==",+ "dependencies": {+ "parseley": "^0.12.0"+ },+ "funding": {+ "url": "https://ko-fi.com/killymxi"+ }+ },"node_modules/semver": {"version": "7.7.2","resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",diff --git a/server/package.json b/server/package.jsonindex 2f852a8e4..3e5f359da 100644--- a/server/package.json+++ b/server/package.json@@ -32,6 +32,7 @@"node-cron": "4.0.5","pg": "8.16.0","postgres": "3.4.5",+ "resend": "^4.5.1","sqlstring": "2.3.3","stripe": "18.1.0","ua-parser-js": "2.0.3",diff --git a/server/src/api/getConfig.ts b/server/src/api/getConfig.tsindex 0d0c2193d..e428a2147 100644--- a/server/src/api/getConfig.ts+++ b/server/src/api/getConfig.ts@@ -1,7 +1,7 @@import { FastifyRequest, FastifyReply } from "fastify";import { DISABLE_SIGNUP } from "../lib/const.js";-export async function getConfig(request: FastifyRequest, reply: FastifyReply) {+export async function getConfig(_: FastifyRequest, reply: FastifyReply) {return reply.send({disableSignup: DISABLE_SIGNUP,});diff --git a/server/src/lib/auth.ts b/server/src/lib/auth.tsindex 3f12b9343..9b645b720 100644--- a/server/src/lib/auth.ts+++ b/server/src/lib/auth.ts@@ -6,7 +6,8 @@ import { eq } from "drizzle-orm";import pg from "pg";import { db } from "../db/postgres/postgres.js";import * as schema from "../db/postgres/schema.js";-import { DISABLE_SIGNUP, IS_CLOUD } from "./const.js";+import { DISABLE_SIGNUP } from "./const.js";+import { sendInvitationEmail } from "./resend.js";dotenv.config();@@ -19,6 +20,15 @@ const pluginList = [allowUserToCreateOrganization: true,// Set the creator role to ownercreatorRole: "owner",+ sendInvitationEmail: async (invitation) => {+ const inviteLink = `${process.env.BASE_URL}/invitation?invitationId=${invitation.invitation.id}&organization=${invitation.organization.name}&inviterEmail=${invitation.inviter.user.email}`;+ await sendInvitationEmail(+ invitation.email,+ invitation.inviter.user.email,+ invitation.organization.name,+ inviteLink+ );+ },}),];diff --git a/server/src/lib/resend.ts b/server/src/lib/resend.tsnew file mode 100644index 000000000..8966e40cb--- /dev/null+++ b/server/src/lib/resend.ts@@ -0,0 +1,166 @@+import { Resend } from "resend";+import { IS_CLOUD } from "./const.js";++let resend: Resend | undefined;++if (IS_CLOUD) {+ resend = new Resend(process.env.RESEND_API_KEY);+}++export const sendEmail = async (+ email: string,+ subject: string,+ html: string+) => {+ if (!resend) {+ return;+ // not sure how to handle self hosted instances without resend+ // throw new Error("Resend is not initialized");+ }+ try {+ const response = await resend.emails.send({+ from: "Rybbit <[email protected]>",+ to: email,+ subject,+ html,+ });+ return response;+ } catch (error) {+ console.error(error);+ throw error;+ }+};++export const sendInvitationEmail = async (+ email: string,+ invitedBy: string,+ organizationName: string,+ inviteLink: string+) => {+ const html = `+ <!DOCTYPE html>+ <html>+ <head>+ <meta charset="utf-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Invitation to Join Rybbit</title>+ <style>+ body {+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;+ line-height: 1.6;+ color: #1a1a1a;+ background-color: #0c0c0c;+ margin: 0;+ padding: 0;+ }+ .email-container {+ max-width: 600px;+ margin: 0 auto;+ padding: 40px 24px;+ background-color: #0c0c0c;+ }+ .header {+ text-align: center;+ padding-bottom: 32px;+ }+ .logo {+ margin: 0 auto;+ display: block;+ }+ .content {+ padding: 0;+ }+ .invite-badge {+ display: inline-block;+ background-color: rgba(16, 185, 129, 0.2);+ color: #10b981;+ padding: 6px 12px;+ border-radius: 50px;+ font-size: 14px;+ font-weight: 500;+ margin-bottom: 16px;+ text-align: center;+ }+ .invite-text {+ font-size: 16px;+ margin-bottom: 32px;+ color: #e5e5e5;+ }+ .highlight {+ font-weight: bold;+ color: #10b981;+ }+ .button-container {+ text-align: center;+ margin: 32px 0;+ }+ .button {+ display: inline-block;+ background-color: #10b981;+ color: white;+ padding: 12px 32px;+ text-decoration: none;+ font-weight: bold;+ border-radius: 6px;+ font-size: 16px;+ transition: background-color 0.3s;+ }+ .button:hover {+ background-color: #059669;+ }+ .footer {+ text-align: center;+ margin-top: 40px;+ padding-top: 20px;+ border-top: 1px solid #27272a;+ font-size: 12px;+ color: #a3a3a3;+ }+ .footer a {+ color: #10b981;+ text-decoration: none;+ }+ .footer a:hover {+ text-decoration: underline;+ }+ h2 {+ color: #ffffff;+ font-size: 28px;+ text-align: center;+ margin-bottom: 24px;+ font-weight: 600;+ }+ p {+ margin: 12px 0;+ }+ </style>+ </head>+ <body>+ <div class="email-container">+ <div class="content">+ <div style="text-align: center;">+ <div class="invite-badge">New Invitation</div>+ <h2>You've Been Invited!</h2>+ </div>+ <div class="invite-text">+ <p>${invitedBy} has invited you to join <span class="highlight">${organizationName}</span> on Rybbit Analytics.</p>+ <p>Rybbit is an open-source analytics platform that helps you understand your website traffic while respecting user privacy.</p>+ </div>+ <div class="button-container">+ <a href="${inviteLink}" class="button">Accept Invitation</a>+ </div>+ </div>+ <div class="footer">+ <p>This invitation was sent to <span class="highlight">${email}</span>.</p>+ <p>© ${new Date().getFullYear()} Rybbit Analytics</p>+ </div>+ </div>+ </body>+ </html>+ `;+ await sendEmail(+ email,+ "You're Invited to Join an Organization on Rybbit",+ html+ );+};