Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
org-secrets.tsx19.6 KB · 627 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/**
 * Org-level secrets UI — Block M1.
 *
 * Routes:
 *   GET  /orgs/:slug/settings/secrets          — list secrets (admin/owner only)
 *   POST /orgs/:slug/settings/secrets          — create or update a secret
 *   POST /orgs/:slug/settings/secrets/:id/delete — delete a secret
 *
 * Auth: requireAuth + org admin/owner check via loadOrgForUser.
 * CSS:  every selector prefixed `.osec-*` — no bleed into other surfaces.
 */

import { Hono } from "hono";
import { Layout } from "../views/layout";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import { loadOrgForUser, orgRoleAtLeast } from "../lib/orgs";
import {
  listOrgSecrets,
  upsertOrgSecret,
  deleteOrgSecret,
} from "../lib/org-secrets";
import { getUnreadCount } from "../lib/unread";

const orgSecretsRoutes = new Hono<AuthEnv>();

// ── Auth guard ────────────────────────────────────────────────────────────────

orgSecretsRoutes.use("/orgs/:slug/settings/secrets*", softAuth, requireAuth);

// ── Scoped CSS (.osec-*) ──────────────────────────────────────────────────────

const osecStyles = `
  .osec-wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-4);
  }

  /* ─── Hero ─── */
  .osec-hero {
    position: relative;
    margin-bottom: var(--space-6);
    padding: var(--space-5) var(--space-6);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }
  .osec-hero::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #8c6dff 30%, #36c5d6 70%, transparent 100%);
    opacity: 0.7;
    pointer-events: none;
  }
  .osec-hero-orb {
    position: absolute;
    inset: -20% -10% auto auto;
    width: 360px; height: 360px;
    background: radial-gradient(circle, rgba(140,109,255,0.20), rgba(54,197,214,0.10) 45%, transparent 70%);
    filter: blur(80px);
    opacity: 0.7;
    pointer-events: none;
    z-index: 0;
  }
  .osec-hero-inner {
    position: relative;
    z-index: 1;
    max-width: 640px;
  }
  .osec-eyebrow {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    font-family: var(--font-mono);
    font-weight: 600;
  }
  .osec-title {
    font-size: clamp(26px, 4vw, 38px);
    font-family: var(--font-display);
    font-weight: 800;
    letter-spacing: -0.028em;
    line-height: 1.05;
    margin: 0 0 var(--space-2);
    color: var(--text-strong);
  }
  .osec-title-grad {
    background-image: linear-gradient(135deg, #a48bff 0%, #8c6dff 50%, #36c5d6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }
  .osec-sub {
    font-size: 14.5px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.55;
  }

  /* ─── Info banner ─── */
  .osec-banner {
    display: flex;
    gap: 12px;
    padding: 14px 18px;
    background: rgba(140,109,255,0.08);
    border: 1px solid rgba(140,109,255,0.22);
    border-radius: 12px;
    margin-bottom: var(--space-5);
    font-size: 13.5px;
    color: var(--text);
    line-height: 1.55;
  }
  .osec-banner-icon {
    flex-shrink: 0;
    width: 18px; height: 18px;
    margin-top: 1px;
    color: #a78bfa;
  }

  /* ─── Flash messages ─── */
  .osec-flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: var(--space-4);
    font-size: 13.5px;
    line-height: 1.45;
  }
  .osec-flash-ok {
    background: rgba(34,197,94,0.10);
    border: 1px solid rgba(34,197,94,0.26);
    color: #86efac;
  }
  .osec-flash-err {
    background: rgba(239,68,68,0.10);
    border: 1px solid rgba(239,68,68,0.28);
    color: #fca5a5;
  }

  /* ─── Form card ─── */
  .osec-form-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: var(--space-5) var(--space-5);
    margin-bottom: var(--space-6);
  }
  .osec-form-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 var(--space-4);
    letter-spacing: -0.01em;
  }
  .osec-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    align-items: end;
  }
  @media (max-width: 640px) {
    .osec-form-row { grid-template-columns: 1fr; }
  }
  .osec-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
    font-family: var(--font-mono);
  }
  .osec-input {
    width: 100%;
    padding: 9px 13px;
    background: var(--bg-input, var(--bg));
    border: 1px solid var(--border-strong, var(--border));
    border-radius: 8px;
    color: var(--text);
    font-size: 13.5px;
    font-family: var(--font-mono);
    box-sizing: border-box;
    transition: border-color 120ms ease, box-shadow 120ms ease;
  }
  .osec-input:focus {
    outline: none;
    border-color: rgba(140,109,255,0.6);
    box-shadow: 0 0 0 3px rgba(140,109,255,0.14);
  }
  .osec-input.is-invalid {
    border-color: rgba(239,68,68,0.6);
  }
  .osec-hint {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 5px;
  }
  .osec-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease;
    white-space: nowrap;
  }
  .osec-btn-primary {
    background: linear-gradient(135deg, #8c6dff 0%, #36c5d6 100%);
    color: #fff;
    box-shadow: 0 5px 16px -4px rgba(140,109,255,0.45);
  }
  .osec-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 9px 22px -6px rgba(140,109,255,0.55);
  }
  .osec-btn-danger {
    background: transparent;
    color: #f87171;
    border-color: rgba(239,68,68,0.35);
    padding: 6px 12px;
    font-size: 12.5px;
  }
  .osec-btn-danger:hover {
    background: rgba(239,68,68,0.08);
    border-color: rgba(239,68,68,0.6);
  }

  /* ─── Secrets table ─── */
  .osec-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 var(--space-3);
    letter-spacing: -0.01em;
  }
  .osec-table-wrap {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
  }
  .osec-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
  }
  .osec-table thead th {
    padding: 10px 16px;
    background: var(--bg-secondary, var(--bg-elevated));
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-mono);
  }
  .osec-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 80ms ease;
  }
  .osec-table tbody tr:last-child { border-bottom: none; }
  .osec-table tbody tr:hover { background: rgba(140,109,255,0.035); }
  .osec-table td {
    padding: 11px 16px;
    color: var(--text);
    vertical-align: middle;
  }
  .osec-name {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-strong);
    font-size: 13px;
  }
  .osec-hint-val {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-size: 12.5px;
  }
  .osec-date {
    font-size: 12.5px;
    color: var(--text-muted);
    font-family: var(--font-mono);
  }
  .osec-actions { text-align: right; }

  /* ─── Empty state ─── */
  .osec-empty {
    padding: 48px 24px;
    text-align: center;
    background: var(--bg-secondary, var(--bg-elevated));
  }
  .osec-empty-icon {
    width: 40px; height: 40px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: rgba(140,109,255,0.12);
    color: #a78bfa;
  }
  .osec-empty-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 6px;
  }
  .osec-empty-sub {
    font-size: 13.5px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
  }

  /* ─── Breadcrumb ─── */
  .osec-crumb {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .osec-crumb a { color: var(--text-muted); text-decoration: none; }
  .osec-crumb a:hover { color: var(--text); }
  .osec-crumb-sep { opacity: 0.4; }
`;

// ── Helpers ───────────────────────────────────────────────────────────────────

function formatDate(d: Date): string {
  return d.toLocaleDateString("en-US", {
    year: "numeric",
    month: "short",
    day: "numeric",
  });
}

// ── GET /orgs/:slug/settings/secrets ─────────────────────────────────────────

orgSecretsRoutes.get("/orgs/:slug/settings/secrets", async (c) => {
  const slug = c.req.param("slug");
  const user = c.get("user")!;

  const { org, role } = await loadOrgForUser(slug, user.id);
  if (!org) return c.notFound();
  if (!role || !orgRoleAtLeast(role, "admin")) {
    return c.redirect(`/orgs/${slug}`);
  }

  const secrets = await listOrgSecrets(org.id);
  const unread = await getUnreadCount(user.id);
  const success = c.req.query("success");
  const error = c.req.query("error");

  return c.html(
    <Layout
      title={`Secrets — ${org.slug}`}
      user={user}
      notificationCount={unread}
    >
      <style dangerouslySetInnerHTML={{ __html: osecStyles }} />

      <div class="osec-wrap">
        {/* Breadcrumb */}
        <nav class="osec-crumb" aria-label="breadcrumb">
          <a href={`/orgs/${org.slug}`}>{org.slug}</a>
          <span class="osec-crumb-sep">/</span>
          <a href={`/orgs/${org.slug}/settings`}>settings</a>
          <span class="osec-crumb-sep">/</span>
          <span>secrets</span>
        </nav>

        {/* Hero */}
        <div class="osec-hero" role="banner">
          <div class="osec-hero-orb" aria-hidden="true" />
          <div class="osec-hero-inner">
            <div class="osec-eyebrow">
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                <rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
                <path d="M7 11V7a5 5 0 0 1 10 0v4" />
              </svg>
              Org secrets
            </div>
            <h1 class="osec-title">
              <span class="osec-title-grad">Secrets.</span>
            </h1>
            <p class="osec-sub">
              Encrypted values available to all workflow runs in{" "}
              <strong>{org.slug}</strong>.
            </p>
          </div>
        </div>

        {/* Flash */}
        {success && (
          <div class="osec-flash osec-flash-ok" role="status">
            <svg class="osec-banner-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
              <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
              <polyline points="22 4 12 14.01 9 11.01" />
            </svg>
            {decodeURIComponent(success)}
          </div>
        )}
        {error && (
          <div class="osec-flash osec-flash-err" role="alert">
            <svg class="osec-banner-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
              <circle cx="12" cy="12" r="10" />
              <line x1="12" y1="8" x2="12" y2="12" />
              <line x1="12" y1="16" x2="12.01" y2="16" />
            </svg>
            {decodeURIComponent(error)}
          </div>
        )}

        {/* Info banner */}
        <div class="osec-banner" role="note">
          <svg class="osec-banner-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <circle cx="12" cy="12" r="10" />
            <line x1="12" y1="8" x2="12" y2="8" />
            <line x1="12" y1="12" x2="12" y2="16" />
          </svg>
          These secrets are available to all workflow runs in this org. They're
          overridden by repo-level secrets of the same name.
        </div>

        {/* Add / update form */}
        <div class="osec-form-card">
          <p class="osec-form-title">Add or update a secret</p>
          <form method="post" action={`/orgs/${org.slug}/settings/secrets`}>
            <div class="osec-form-row">
              <div>
                <label class="osec-label" for="osec-name">Name</label>
                <input
                  id="osec-name"
                  class="osec-input"
                  type="text"
                  name="name"
                  required
                  placeholder="MY_SECRET_NAME"
                  pattern="[A-Z_][A-Z0-9_]*"
                  maxLength={100}
                  autocomplete="off"
                  spellcheck={false}
                  oninput="this.value=this.value.toUpperCase().replace(/[^A-Z0-9_]/g,'');this.classList.toggle('is-invalid',this.value.length>0&&!/^[A-Z_][A-Z0-9_]*$/.test(this.value))"
                />
                <p class="osec-hint">
                  Uppercase letters, digits, underscores — must start with a letter or
                  underscore.
                </p>
              </div>
              <div>
                <label class="osec-label" for="osec-value">Value</label>
                <input
                  id="osec-value"
                  class="osec-input"
                  type="password"
                  name="value"
                  required
                  placeholder="••••••••••••"
                  autocomplete="new-password"
                />
                <p class="osec-hint">Value is encrypted at rest with AES-256-GCM.</p>
              </div>
              <div>
                <button type="submit" class="osec-btn osec-btn-primary">
                  Save secret
                </button>
              </div>
            </div>
          </form>
        </div>

        {/* Secrets list */}
        <p class="osec-section-title">
          {secrets.length === 0
            ? "No secrets yet"
            : `${secrets.length} secret${secrets.length === 1 ? "" : "s"}`}
        </p>

        {secrets.length === 0 ? (
          <div class="osec-table-wrap">
            <div class="osec-empty">
              <div class="osec-empty-icon" aria-hidden="true">
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                  <rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
                  <path d="M7 11V7a5 5 0 0 1 10 0v4" />
                </svg>
              </div>
              <p class="osec-empty-title">No secrets configured</p>
              <p class="osec-empty-sub">
                Add your first secret above. It will be injected into every
                workflow run inside <strong>{org.slug}</strong> as{" "}
                <code>{"${{ secrets.NAME }}"}</code>.
              </p>
            </div>
          </div>
        ) : (
          <div class="osec-table-wrap">
            <table class="osec-table" aria-label="Org secrets">
              <thead>
                <tr>
                  <th scope="col">Name</th>
                  <th scope="col">Hint</th>
                  <th scope="col">Updated</th>
                  <th scope="col">
                    <span class="sr-only">Actions</span>
                  </th>
                </tr>
              </thead>
              <tbody>
                {secrets.map((s) => (
                  <tr key={s.id}>
                    <td>
                      <span class="osec-name">{s.name}</span>
                    </td>
                    <td>
                      <span class="osec-hint-val">
                        {s.keyHint ? `••••${s.keyHint}` : "—"}
                      </span>
                    </td>
                    <td>
                      <span class="osec-date">{formatDate(s.updatedAt)}</span>
                    </td>
                    <td class="osec-actions">
                      <form
                        method="post"
                        action={`/orgs/${org.slug}/settings/secrets/${s.id}/delete`}
                        onsubmit="return confirm('Delete this secret? This cannot be undone.')"
                      >
                        <button type="submit" class="osec-btn osec-btn-danger">
                          Delete
                        </button>
                      </form>
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        )}
      </div>
    </Layout>
  );
});

// ── POST /orgs/:slug/settings/secrets ─────────────────────────────────────────

orgSecretsRoutes.post("/orgs/:slug/settings/secrets", async (c) => {
  const slug = c.req.param("slug");
  const user = c.get("user")!;

  const { org, role } = await loadOrgForUser(slug, user.id);
  if (!org) return c.notFound();
  if (!role || !orgRoleAtLeast(role, "admin")) {
    return c.redirect(`/orgs/${slug}`);
  }

  const body = await c.req.parseBody();
  const name = String(body.name ?? "").trim();
  const value = String(body.value ?? "");

  if (!name || !value) {
    const msg = encodeURIComponent("Name and value are required.");
    return c.redirect(`/orgs/${slug}/settings/secrets?error=${msg}`);
  }

  try {
    await upsertOrgSecret(org.id, name, value, user.id);
  } catch (err) {
    const msg = encodeURIComponent(
      err instanceof Error ? err.message : "Failed to save secret."
    );
    return c.redirect(`/orgs/${slug}/settings/secrets?error=${msg}`);
  }

  const ok = encodeURIComponent(`Secret "${name}" saved.`);
  return c.redirect(`/orgs/${slug}/settings/secrets?success=${ok}`);
});

// ── POST /orgs/:slug/settings/secrets/:id/delete ──────────────────────────────

orgSecretsRoutes.post("/orgs/:slug/settings/secrets/:id/delete", async (c) => {
  const slug = c.req.param("slug");
  const secretId = c.req.param("id");
  const user = c.get("user")!;

  const { org, role } = await loadOrgForUser(slug, user.id);
  if (!org) return c.notFound();
  if (!role || !orgRoleAtLeast(role, "admin")) {
    return c.redirect(`/orgs/${slug}`);
  }

  try {
    await deleteOrgSecret(org.id, secretId);
  } catch (err) {
    const msg = encodeURIComponent(
      err instanceof Error ? err.message : "Failed to delete secret."
    );
    return c.redirect(`/orgs/${slug}/settings/secrets?error=${msg}`);
  }

  const ok = encodeURIComponent("Secret deleted.");
  return c.redirect(`/orgs/${slug}/settings/secrets?success=${ok}`);
});

export default orgSecretsRoutes;