diff --git a/core/api/service_account.go b/core/api/service_account.go index 6a4b67b..d0b4c80 100644 --- a/core/api/service_account.go +++ b/core/api/service_account.go @@ -174,7 +174,7 @@ func GetServiceAccountToken(c *gin.Context) { RequestTokenHasEntityID(c, sa.CreatedBy), RequestUserIsAdmin(c), )) - if sa.SignedToken == "" { + if sa.ActiveToken == nil || sa.SignedToken == "" { c.JSON(http.StatusNotFound, gin.H{"error": "no active token; rotate to mint a new one"}) return } diff --git a/web/src/pages/applications/ServiceAccountsCard.tsx b/web/src/pages/applications/ServiceAccountsCard.tsx index 5749be4..8c58dbb 100644 --- a/web/src/pages/applications/ServiceAccountsCard.tsx +++ b/web/src/pages/applications/ServiceAccountsCard.tsx @@ -7,7 +7,7 @@ import { RefreshCw, Trash2, } from "lucide-react" -import { useEffect, useState } from "react" +import { useState } from "react" import { toast } from "sonner" import { OutlineButton } from "@/components/OutlineButton" @@ -131,15 +131,17 @@ export function ServiceAccountsCard({ applicationID }: { applicationID: string } - { - setCreateOpen(false) - setRevealed(result) - }} - /> + {createOpen && ( + { + setCreateOpen(false) + setRevealed(result) + }} + /> + )}
@@ -190,15 +202,26 @@ function ServiceAccountItem({
{canViewToken && hasActiveToken && ( - + <> + + + )}
New service account - A service account gets one bearer JWT, shown once{" "} - after creation. Pick a name that's clear about what this account - does and the scopes it needs. + A service account gets one bearer JWT. The creator and admins + can reveal or copy the active token later. @@ -505,8 +519,10 @@ function RevealTokenDialog({ }) { function copyToken() { if (!result) return - void navigator.clipboard.writeText(result.token) - toast.success("Token copied") + void navigator.clipboard + .writeText(result.token) + .then(() => toast.success("Token copied")) + .catch(() => toast.error("Couldn't copy token.")) } return ( @@ -523,9 +539,8 @@ function RevealTokenDialog({ Copy your bearer token - This is the only time the full token for{" "} - {result?.service_account.name} will be shown. - Save it somewhere safe — if you lose it you'll have to rotate. + The active token for {result?.service_account.name}. + The creator and admins can reveal or copy it again later.