File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,11 +13,12 @@ export type DecodedCredentials = {
1313
1414export type Info = {
1515 readonly password : Option . Option < string >
16+ readonly username : string
1617}
1718
1819export 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) {
3233export 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}
Original file line number Diff line number Diff 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" )
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { ServerAuth } from "@opencode-ai/server/auth"
33import { Option , Redacted } from "effect"
44
55test ( "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} )
You can’t perform that action at this time.
0 commit comments