mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 3: Phase 3: Shared Manager auth helper and Manager API client f
This commit is contained in:
1 parent
b316cb960c
commit
a99e69f653
5 files changed
+427
-27
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { readState } from './state.js'
|
||||
import { getToken } from './internal-token-store.js'
|
||||
import { TokenStoreError } from './token-store.js'
|
||||
|
||||
export type ManagerAuth =
|
||||
| { ok: true; managerUrl: string; token: string }
|
||||
| { ok: false; message: string }
|
||||
|
||||
export async function resolveManagerAuth(
|
||||
managerUrl: string | undefined = readState()?.managerUrl,
|
||||
): Promise<ManagerAuth> {
|
||||
if (!managerUrl) {
|
||||
return { ok: false, message: 'No manager configured. Run `ocm login <url>` first.' }
|
||||
}
|
||||
|
||||
let token: string | null
|
||||
try {
|
||||
token = await getToken(managerUrl)
|
||||
} catch (err) {
|
||||
const reason = err instanceof TokenStoreError ? err.message : String(err)
|
||||
return { ok: false, message: `Token store unavailable: ${reason}` }
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
return { ok: false, message: `No token stored. Run \`ocm login ${managerUrl}\`.` }
|
||||
}
|
||||
|
||||
return { ok: true, managerUrl, token }
|
||||
}
|
||||
Reference in new issue
Block a user