Fix API token creation error by correcting date formatting and adding default permissions logic.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/29294a5b-df23-4880-bdc0-45834e9d7395.jpg
This commit is contained in:
alphaeusmote
2025-04-11 17:27:19 +00:00
parent c3c8a1716b
commit b791c7110e
2 changed files with 56 additions and 22 deletions
+16 -8
View File
@@ -126,7 +126,7 @@ export default function ApiTokensPage() {
// Add token mutation
const addTokenMutation = useMutation({
mutationFn: async (data: z.infer<typeof tokenFormSchema>) => {
const tokenData: Partial<InsertApiToken> = {
const tokenData: Partial<any> = {
name: data.name,
organizationId: currentOrganization?.id || "",
role: data.role,
@@ -157,30 +157,38 @@ export default function ApiTokensPage() {
customDate.setHours(23, 59, 59, 999);
}
tokenData.expiresAt = customDate;
// Server expects ISO string for dates, not JavaScript Date objects
tokenData.expiresAt = customDate.toISOString();
}
} else {
// For preset expiration options
let expiresAt: Date;
switch (data.expiresIn) {
case '1hour':
tokenData.expiresAt = new Date(now.getTime() + 60 * 60 * 1000);
expiresAt = new Date(now.getTime() + 60 * 60 * 1000);
break;
case '1day':
tokenData.expiresAt = new Date(now.getTime() + 24 * 60 * 60 * 1000);
expiresAt = new Date(now.getTime() + 24 * 60 * 60 * 1000);
break;
case '7days':
tokenData.expiresAt = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
expiresAt = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
break;
case '30days':
tokenData.expiresAt = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000);
expiresAt = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000);
break;
case '90days':
tokenData.expiresAt = new Date(now.getTime() + 90 * 24 * 60 * 60 * 1000);
expiresAt = new Date(now.getTime() + 90 * 24 * 60 * 60 * 1000);
break;
case '1year':
tokenData.expiresAt = new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000);
expiresAt = new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000);
break;
default:
expiresAt = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000);
}
// Server expects ISO string for dates, not JavaScript Date objects
tokenData.expiresAt = expiresAt.toISOString();
}
}