Skip to content

Commit 40efbe8

Browse files
fix(scripts): unify Fly.io auth header handling (tldraw#8591)
`fetch-fly-logs.ts` was sending the raw token as the `Authorization` header, while `fetch-fly-metrics.ts` correctly used the `FlyV1 <token>` format. Additionally, if a user passed a token that already included the `FlyV1 ` prefix (e.g. copied from a password manager), the metrics script would double-prefix it. This PR fixes both issues: - `getFlyToken()` now strips any existing `FlyV1 ` prefix, so callers always get a raw token - `fetch-fly-logs.ts` now uses `FlyV1 ${token}` like `fetch-fly-metrics.ts` ### Change type - [x] `bugfix` ### Test plan 1. Run `fetch-fly-logs.ts` with a token that includes the `FlyV1 ` prefix — should work 2. Run `fetch-fly-logs.ts` with a raw token — should work 3. Run `fetch-fly-metrics.ts` with both token formats — should still work ### Code changes | Section | LOC change | | -------------- | ---------- | | Config/tooling | +11 / -7 |
1 parent a0990db commit 40efbe8

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

internal/scripts/fetch-fly-logs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function main() {
8686
const token = getFlyToken(opts.token)
8787
const url = `${BASE_URL}?${params}`
8888

89-
const res = await fetch(url, { headers: { Authorization: token } })
89+
const res = await fetch(url, { headers: { Authorization: `FlyV1 ${token}` } })
9090
if (!res.ok) {
9191
console.error(`HTTP ${res.status}: ${await res.text()}`)
9292
process.exit(1)

internal/scripts/fly-common.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
export const FLY_ORG_SLUG = process.env.FLY_ORG_SLUG ?? 'tldraw-gb-ltd'
1313

1414
export function getFlyToken(explicit?: string): string {
15-
if (explicit) return explicit
16-
if (process.env.FLY_TOKEN) return process.env.FLY_TOKEN
17-
console.error(
18-
'No token provided. Use --token, FLY_TOKEN env var, or create one with: fly tokens create readonly'
19-
)
20-
process.exit(1)
15+
let token = explicit ?? process.env.FLY_TOKEN
16+
if (!token) {
17+
console.error(
18+
'No token provided. Use --token, FLY_TOKEN env var, or create one with: fly tokens create readonly'
19+
)
20+
process.exit(1)
21+
}
22+
// Strip "FlyV1 " prefix if present — callers add it themselves
23+
if (token.startsWith('FlyV1 ')) token = token.slice(6)
24+
return token
2125
}
2226

2327
export function parseDuration(s: string, unit: 'ms' | 's' = 's'): number {

0 commit comments

Comments
 (0)