| 1 | "use client"; |
| 2 | |
| 3 | import { KeyRound } from |
| 4 | import { useAction } |
| 5 | import { toast } |
| 6 | |
| 7 | import { CopyField } |
| 8 | import { rotateOauthAppSecret } |
| 9 | import { SecretAlert } |
| 10 | import { |
| 11 | AlertDialog, |
| 12 | AlertDialogAction, |
| 13 | AlertDialogCancel, |
| 14 | AlertDialogContent, |
| 15 | AlertDialogDescription, |
| 16 | AlertDialogFooter, |
| 17 | AlertDialogHeader, |
| 18 | AlertDialogTitle, |
| 19 | AlertDialogTrigger, |
| 20 | } from "@/components/ui/alert-dialog"; |
| 21 | import { Button } |
| 22 | import { Card, CardContent |
| 23 | import { Field, FieldDescription |
| 24 | import { Spinner } |
| 25 | |
| 26 | /** The client ID to copy, and a new client secret when the old one is lost or leaked. */ |
| 27 | export function OauthAppCredentials({ |
| 28 | app, |
| 29 | }: { |
| 30 | app: { |
| 31 | }) { |
| 32 | const rotate = |
| 33 | onError: ({ error |
| 34 | toast.error(error |
| 35 | }); |
| 36 | const secret = |
| 37 | |
| 38 | return ( |
| 39 | <section className="flex flex-col gap-3 |
| 40 | <h2 className="text-sm font-semibold |
| 41 | {secret && ( |
| 42 | <SecretAlert |
| 43 | title="Copy the new client secret now" |
| 44 | description="Ghost will not show it again. The previous secret has already stopped working, so update your app's configuration." |
| 45 | secret={secret} |
| 46 | /> |
| 47 | )} |
| 48 | <Card> |
| 49 | <CardContent className=" |
| 50 | <CopyField |
| 51 | id="client-id" |
| 52 | label="Client ID" |
| 53 | value={app.clientId |
| 54 | description="Public. Your app sends it when it asks people for access." |
| 55 | /> |
| 56 | <Field> |
| 57 | <FieldLabel>Client secret</FieldLabel |
| 58 | <div className="flex flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between |
| 59 | <FieldDescription> |
| 60 | Ghost keeps only a hash, so it cannot show the secret again. |
| 61 | Generate a new one if you lost it or it leaked. |
| 62 | </FieldDescription> |
| 63 | <AlertDialog> |
| 64 | <AlertDialogTrigger asChild> |
| 65 | <Button variant=" |
| 66 | <KeyRound /> |
| 67 | Generate a new secret |
| 68 | </Button> |
| 69 | </AlertDialogTrigger> |
| 70 | <AlertDialogContent> |
| 71 | <AlertDialogHeader> |
| 72 | <AlertDialogTitle>Generate a new secret?</AlertDialogTitle |
| 73 | <AlertDialogDescription> |
| 74 | The current secret stops working at once. {app.name}{" |
| 75 | cannot sign anyone in until it has the new one. |
| 76 | </AlertDialogDescription> |
| 77 | </AlertDialogHeader> |
| 78 | <AlertDialogFooter> |
| 79 | <AlertDialogCancel>Cancel</AlertDialogCancel |
| 80 | <AlertDialogAction |
| 81 | disabled={rotate.isExecuting |
| 82 | onClick={() => |
| 83 | > |
| 84 | {rotate.isExecuting && |
| 85 | Generate new secret |
| 86 | </AlertDialogAction> |
| 87 | </AlertDialogFooter> |
| 88 | </AlertDialogContent> |
| 89 | </AlertDialog> |
| 90 | </div> |
| 91 | </Field> |
| 92 | </CardContent> |
| 93 | </Card> |
| 94 | </section> |
| 95 | ); |
| 96 | } |