mirror of
https://github.com/documenso/documenso.git
synced 2026-08-23 14:52:23 +10:00
feat: track when API tokens were last used
This commit is contained in:
@@ -68,6 +68,20 @@ export default function ApiTokensPage() {
|
|||||||
return i18n.date(row.original.expires);
|
return i18n.date(row.original.expires);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
header: t`Last Used`,
|
||||||
|
cell: ({ row }) => {
|
||||||
|
if (!row.original.lastUsedAt) {
|
||||||
|
return (
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
<Trans>Never</Trans>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <span className="text-foreground">{i18n.date(row.original.lastUsedAt)}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
header: t`Actions`,
|
header: t`Actions`,
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
|
|||||||
@@ -96,6 +96,17 @@ export const getApiTokenByToken = async ({ token, bypassRateLimit = false }: Get
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void prisma.apiToken
|
||||||
|
.update({
|
||||||
|
where: {
|
||||||
|
id: apiToken.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
lastUsedAt: new Date(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...apiToken,
|
...apiToken,
|
||||||
user,
|
user,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const getApiTokens = async ({ userId, teamId }: GetApiTokensOptions) => {
|
|||||||
name: true,
|
name: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
expires: true,
|
expires: true,
|
||||||
|
lastUsedAt: true,
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'desc',
|
createdAt: 'desc',
|
||||||
|
|||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ApiToken" ADD COLUMN "lastUsedAt" TIMESTAMP(3);
|
||||||
@@ -220,16 +220,17 @@ enum ApiTokenAlgorithm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model ApiToken {
|
model ApiToken {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String
|
name String
|
||||||
token String @unique
|
token String @unique
|
||||||
algorithm ApiTokenAlgorithm @default(SHA512)
|
algorithm ApiTokenAlgorithm @default(SHA512)
|
||||||
expires DateTime?
|
expires DateTime?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
userId Int?
|
lastUsedAt DateTime?
|
||||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
userId Int?
|
||||||
teamId Int
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
teamId Int
|
||||||
|
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SubscriptionStatus {
|
enum SubscriptionStatus {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const ZGetApiTokensResponseSchema = z.array(
|
|||||||
name: true,
|
name: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
expires: true,
|
expires: true,
|
||||||
|
lastUsedAt: true,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user