From fc7e4cf93e660ad5ddabb0c48ecc99e934ebfe95 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Mon, 20 Jul 2026 21:46:23 -0400 Subject: [PATCH] fix(server): preserve v1 auth compatibility --- packages/server/src/auth.ts | 7 ++++--- packages/server/src/process.ts | 2 +- packages/server/test/auth.test.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/server/src/auth.ts b/packages/server/src/auth.ts index 1f9632fede..5f016d75e0 100644 --- a/packages/server/src/auth.ts +++ b/packages/server/src/auth.ts @@ -13,11 +13,12 @@ export type DecodedCredentials = { export type Info = { readonly password: Option.Option + readonly username: string } export class Config extends Context.Service()("@opencode/ServerAuthConfig") { - static configLayer(input: Info) { - return Layer.succeed(this, this.of(input)) + static configLayer(input: Pick) { + return Layer.succeed(this, this.of({ ...input, username: "opencode" })) } static get layer() { @@ -32,7 +33,7 @@ export function required(config: Info) { export function authorized(credentials: DecodedCredentials, config: Info) { return ( Option.isSome(config.password) && - credentials.username === "opencode" && + credentials.username === config.username && Redacted.value(credentials.password) === config.password.value ) } diff --git a/packages/server/src/process.ts b/packages/server/src/process.ts index b8559cdcf7..c3b01b0140 100644 --- a/packages/server/src/process.ts +++ b/packages/server/src/process.ts @@ -148,7 +148,7 @@ function dispatch( application: Ref.Ref>, shutdown: Deferred.Deferred, ): App { - const auth = ServerAuth.Config.of({ password: Option.some(password) }) + const auth = ServerAuth.Config.of({ password: Option.some(password), username: "opencode" }) return Effect.gen(function* () { const request = yield* HttpServerRequest.HttpServerRequest const url = new URL(request.url, "http://localhost") diff --git a/packages/server/test/auth.test.ts b/packages/server/test/auth.test.ts index f113cfab1d..dc160cb290 100644 --- a/packages/server/test/auth.test.ts +++ b/packages/server/test/auth.test.ts @@ -3,7 +3,7 @@ import { ServerAuth } from "@opencode-ai/server/auth" import { Option, Redacted } from "effect" test("accepts only the fixed opencode username", () => { - const config = { password: Option.some("secret") } + const config = { password: Option.some("secret"), username: "opencode" } expect(ServerAuth.authorized({ username: "opencode", password: Redacted.make("secret") }, config)).toBe(true) expect(ServerAuth.authorized({ username: "custom", password: Redacted.make("secret") }, config)).toBe(false) })