-
Notifications
You must be signed in to change notification settings - Fork 0
agent: @U0AJM7X8FBR Admin - Privy login data. #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sweetmantech
wants to merge
1
commit into
main
Choose a base branch
from
agent/-u0ajm7x8fbr-admin---privy-log-1773755848646
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { Metadata } from "next"; | ||
| import PrivyLoginsPage from "@/components/PrivyLogins/PrivyLoginsPage"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "Privy Logins — Recoup Admin", | ||
| }; | ||
|
|
||
| export default function Page() { | ||
| return <PrivyLoginsPage />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import PageBreadcrumb from "@/components/Sandboxes/PageBreadcrumb"; | ||
| import ApiDocsLink from "@/components/ApiDocsLink"; | ||
| import { usePrivyLogins } from "@/hooks/usePrivyLogins"; | ||
| import PrivyLoginsTable from "@/components/PrivyLogins/PrivyLoginsTable"; | ||
| import type { PrivyLoginsPeriod } from "@/types/privy"; | ||
|
|
||
| const PERIODS: { value: PrivyLoginsPeriod; label: string }[] = [ | ||
| { value: "daily", label: "Daily" }, | ||
| { value: "weekly", label: "Weekly" }, | ||
| { value: "monthly", label: "Monthly" }, | ||
| ]; | ||
|
|
||
| export default function PrivyLoginsPage() { | ||
| const [period, setPeriod] = useState<PrivyLoginsPeriod>("daily"); | ||
| const { data, isLoading, error } = usePrivyLogins(period); | ||
|
|
||
| return ( | ||
| <main className="mx-auto max-w-6xl px-4 py-10"> | ||
| <div className="mb-6 flex items-start justify-between"> | ||
| <div> | ||
| <PageBreadcrumb current="Privy Logins" /> | ||
| <h1 className="text-2xl font-bold tracking-tight text-gray-900 dark:text-gray-100"> | ||
| Privy Logins | ||
| </h1> | ||
| <p className="mt-1 text-sm text-gray-500 dark:text-gray-400"> | ||
| User sign-ins via Privy, grouped by time period. | ||
| </p> | ||
| </div> | ||
| <ApiDocsLink path="admins/privy" /> | ||
| </div> | ||
|
|
||
| <div className="mb-6 flex items-center gap-4"> | ||
| <div className="flex rounded-lg border bg-white dark:bg-gray-900 overflow-hidden"> | ||
| {PERIODS.map(({ value, label }) => ( | ||
| <button | ||
| key={value} | ||
| onClick={() => setPeriod(value)} | ||
| className={`px-4 py-2 text-sm font-medium transition-colors ${ | ||
| period === value | ||
| ? "bg-gray-900 text-white dark:bg-white dark:text-gray-900" | ||
| : "text-gray-600 hover:bg-gray-50 dark:text-gray-400 dark:hover:bg-gray-800" | ||
| }`} | ||
| > | ||
| {label} | ||
| </button> | ||
| ))} | ||
| </div> | ||
|
|
||
| {data && ( | ||
| <span className="text-sm text-gray-500 dark:text-gray-400"> | ||
| <span className="font-semibold text-gray-900 dark:text-gray-100">{data.total}</span>{" "} | ||
| login{data.total !== 1 ? "s" : ""} | ||
| </span> | ||
| )} | ||
| </div> | ||
|
|
||
| {isLoading && ( | ||
| <div className="flex items-center justify-center py-12 text-sm text-gray-400"> | ||
| Loading logins… | ||
| </div> | ||
| )} | ||
|
|
||
| {error && ( | ||
| <div className="rounded-md bg-red-50 p-4 text-sm text-red-700 dark:bg-red-900/20 dark:text-red-400"> | ||
| {error instanceof Error ? error.message : "Failed to load Privy logins"} | ||
| </div> | ||
| )} | ||
|
|
||
| {!isLoading && !error && data && data.logins.length === 0 && ( | ||
| <div className="flex items-center justify-center py-12 text-sm text-gray-400"> | ||
| No logins found for this period. | ||
| </div> | ||
| )} | ||
|
|
||
| {!isLoading && !error && data && data.logins.length > 0 && ( | ||
| <PrivyLoginsTable logins={data.logins} /> | ||
| )} | ||
| </main> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeader, | ||
| TableRow, | ||
| } from "@/components/ui/table"; | ||
| import type { PrivyLoginRow } from "@/types/privy"; | ||
|
|
||
| interface PrivyLoginsTableProps { | ||
| logins: PrivyLoginRow[]; | ||
| } | ||
|
|
||
| export default function PrivyLoginsTable({ logins }: PrivyLoginsTableProps) { | ||
| return ( | ||
| <div className="rounded-md border"> | ||
| <Table> | ||
| <TableHeader> | ||
| <TableRow> | ||
| <TableHead>Email</TableHead> | ||
| <TableHead>Privy DID</TableHead> | ||
| <TableHead>Created At</TableHead> | ||
| </TableRow> | ||
| </TableHeader> | ||
| <TableBody> | ||
| {logins.map((login) => ( | ||
| <TableRow key={login.privy_did}> | ||
| <TableCell className="font-medium"> | ||
| {login.email ?? <span className="text-gray-400 italic">No email</span>} | ||
| </TableCell> | ||
| <TableCell className="font-mono text-xs text-gray-500">{login.privy_did}</TableCell> | ||
| <TableCell className="text-sm text-gray-600 dark:text-gray-400"> | ||
| {new Date(login.created_at).toLocaleString()} | ||
| </TableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| "use client"; | ||
|
|
||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { usePrivy } from "@privy-io/react-auth"; | ||
| import { fetchPrivyLogins } from "@/lib/recoup/fetchPrivyLogins"; | ||
| import type { PrivyLoginsPeriod } from "@/types/privy"; | ||
|
|
||
| /** | ||
| * Fetches Privy login statistics for the given period from GET /api/admins/privy. | ||
| * Authenticates with the Privy access token (admin Bearer auth). | ||
| */ | ||
| export function usePrivyLogins(period: PrivyLoginsPeriod) { | ||
| const { ready, authenticated, getAccessToken } = usePrivy(); | ||
|
|
||
| return useQuery({ | ||
| queryKey: ["admin", "privy", "logins", period], | ||
| queryFn: async () => { | ||
| const token = await getAccessToken(); | ||
| if (!token) throw new Error("Not authenticated"); | ||
| return fetchPrivyLogins(token, period); | ||
| }, | ||
| enabled: ready && authenticated, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { API_BASE_URL } from "@/lib/consts"; | ||
| import type { PrivyLoginsPeriod, PrivyLoginsResponse } from "@/types/privy"; | ||
|
|
||
| /** | ||
| * Fetches Privy login statistics from GET /api/admins/privy. | ||
| * Authenticates using the caller's Privy access token (admin Bearer auth). | ||
| * | ||
| * @param accessToken - Privy access token from getAccessToken() | ||
| * @param period - Time period: "daily", "weekly", or "monthly" | ||
| * @returns PrivyLoginsResponse with total count and login rows | ||
| */ | ||
| export async function fetchPrivyLogins( | ||
| accessToken: string, | ||
| period: PrivyLoginsPeriod, | ||
| ): Promise<PrivyLoginsResponse> { | ||
| const url = new URL(`${API_BASE_URL}/api/admins/privy`); | ||
| url.searchParams.set("period", period); | ||
|
|
||
| const res = await fetch(url.toString(), { | ||
| headers: { Authorization: `Bearer ${accessToken}` }, | ||
| }); | ||
|
|
||
| if (!res.ok) { | ||
| const body = await res.json().catch(() => ({})); | ||
| throw new Error(body.error ?? body.message ?? `HTTP ${res.status}`); | ||
| } | ||
|
|
||
| return res.json(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export type PrivyLoginsPeriod = "daily" | "weekly" | "monthly"; | ||
|
|
||
| export type PrivyLoginRow = { | ||
| privy_did: string; | ||
| email: string | null; | ||
| created_at: string; | ||
| }; | ||
|
|
||
| export type PrivyLoginsResponse = { | ||
| status: "success" | "error"; | ||
| total: number; | ||
| logins: PrivyLoginRow[]; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: recoupable/admin
Length of output: 114
🏁 Script executed:
Repository: recoupable/admin
Length of output: 1234
🏁 Script executed:
Repository: recoupable/admin
Length of output: 1042
🏁 Script executed:
Repository: recoupable/admin
Length of output: 1573
🏁 Script executed:
Repository: recoupable/admin
Length of output: 290
🏁 Script executed:
rg "type PrivyLoginRow|type PrivyLoginsResponse|interface PrivyLogin" --type tsRepository: recoupable/admin
Length of output: 233
🏁 Script executed:
Repository: recoupable/admin
Length of output: 430
Using
privy_didalone as the React key will cause reconciliation issues.Since each
PrivyLoginRowrepresents a distinct login event (note thecreated_atfield), the same user can appear multiple times in a single period with different login timestamps. Using onlyprivy_didas the key will produce duplicate keys, causing React reconciliation failures.Use a compound key that includes
created_at:🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents