Commit accecdb
committed
Make api_tokens.json authoritative source for API tokens (fixes #685)
This is the proper architectural fix for #685. The previous commit was a
bandaid that prevented unnecessary .env writes. This commit addresses the
root cause: dual-source-of-truth for API tokens (.env vs api_tokens.json).
Changes:
1. Startup Migration (config.go:896-951):
- When loading config, if API_TOKEN/API_TOKENS exist in .env but not in
api_tokens.json, automatically migrate them
- Migrated tokens are named "Migrated from .env (prefix)" for clarity
- Logs a deprecation warning: API_TOKEN/API_TOKENS in .env are deprecated
- Leaves .env untouched (safe for existing deployments)
2. Config Watcher Changes (watcher.go:338-424):
- Only load tokens from .env if api_tokens.json is EMPTY
- Once api_tokens.json has records, it becomes the authoritative source
- .env changes no longer trigger token overwrites when api_tokens.json exists
- Logs debug message when ignoring env tokens
Result:
- Existing deployments: env tokens automatically migrated to api_tokens.json
- UI-created tokens: never overwritten by .env changes
- Dark mode toggle: no longer triggers token reload from .env
- Backward compatible: fresh installs with API_TOKEN in .env still work
- Migration path: users can safely keep API_TOKEN in .env, it will be ignored
Future improvement: Add UI warning when API_TOKEN/API_TOKENS still present
in .env, prompting users to rotate tokens via the UI.1 parent 5d99fc2 commit accecdb
2 files changed
+34
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
896 | 896 | | |
897 | 897 | | |
898 | 898 | | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
899 | 904 | | |
900 | 905 | | |
901 | 906 | | |
| |||
909 | 914 | | |
910 | 915 | | |
911 | 916 | | |
912 | | - | |
913 | | - | |
914 | | - | |
| 917 | + | |
915 | 918 | | |
916 | 919 | | |
| 920 | + | |
917 | 921 | | |
918 | 922 | | |
919 | 923 | | |
920 | 924 | | |
| 925 | + | |
921 | 926 | | |
922 | 927 | | |
923 | | - | |
| 928 | + | |
924 | 929 | | |
925 | 930 | | |
926 | 931 | | |
927 | 932 | | |
928 | 933 | | |
929 | 934 | | |
930 | 935 | | |
| 936 | + | |
| 937 | + | |
931 | 938 | | |
| 939 | + | |
932 | 940 | | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
933 | 952 | | |
934 | 953 | | |
935 | 954 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | | - | |
| 338 | + | |
| 339 | + | |
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
| |||
347 | 348 | | |
348 | 349 | | |
349 | 350 | | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | 351 | | |
354 | 352 | | |
355 | 353 | | |
356 | 354 | | |
357 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
358 | 358 | | |
359 | 359 | | |
360 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
361 | 364 | | |
362 | 365 | | |
363 | 366 | | |
| |||
416 | 419 | | |
417 | 420 | | |
418 | 421 | | |
| 422 | + | |
| 423 | + | |
419 | 424 | | |
420 | 425 | | |
421 | 426 | | |
| |||
0 commit comments