Skip to content

Commit fc7e4cf

Browse files
committed
fix(server): preserve v1 auth compatibility
1 parent 43c0838 commit fc7e4cf

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎packages/server/src/auth.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ export type DecodedCredentials = {
1313

1414
export type Info = {
1515
readonly password: Option.Option<string>
16+
readonly username: string
1617
}
1718

1819
export class Config extends Context.Service<Config, Info>()("@opencode/ServerAuthConfig") {
19-
static configLayer(input: Info) {
20-
return Layer.succeed(this, this.of(input))
20+
static configLayer(input: Pick<Info, "password">) {
21+
return Layer.succeed(this, this.of({ ...input, username: "opencode" }))
2122
}
2223

2324
static get layer() {
@@ -32,7 +33,7 @@ export function required(config: Info) {
3233
export function authorized(credentials: DecodedCredentials, config: Info) {
3334
return (
3435
Option.isSome(config.password) &&
35-
credentials.username === "opencode" &&
36+
credentials.username === config.username &&
3637
Redacted.value(credentials.password) === config.password.value
3738
)
3839
}

‎packages/server/src/process.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function dispatch(
148148
application: Ref.Ref<Option.Option<App>>,
149149
shutdown: Deferred.Deferred<void>,
150150
): App {
151-
const auth = ServerAuth.Config.of({ password: Option.some(password) })
151+
const auth = ServerAuth.Config.of({ password: Option.some(password), username: "opencode" })
152152
return Effect.gen(function* () {
153153
const request = yield* HttpServerRequest.HttpServerRequest
154154
const url = new URL(request.url, "http://localhost")

‎packages/server/test/auth.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ServerAuth } from "@opencode-ai/server/auth"
33
import { Option, Redacted } from "effect"
44

55
test("accepts only the fixed opencode username", () => {
6-
const config = { password: Option.some("secret") }
6+
const config = { password: Option.some("secret"), username: "opencode" }
77
expect(ServerAuth.authorized({ username: "opencode", password: Redacted.make("secret") }, config)).toBe(true)
88
expect(ServerAuth.authorized({ username: "custom", password: Redacted.make("secret") }, config)).toBe(false)
99
})

0 commit comments

Comments
 (0)