@@ -43,13 +43,14 @@ class AuthStore {
4343 private readonly broadListeners : Array < ( connection : AuthenticatedConnection , id : EntityIds ) => void > = [ ] ;
4444 private readonly specificListeners : Record < EntityIds , Array < ( connection : AuthenticatedConnection , id : EntityIds ) => void > > = { } ;
4545
46- private readonly localStorageKey = 'Studio:PotentiallyAuthenticated' ;
46+ private readonly potentiallyAuthenticatedKey = 'Studio:PotentiallyAuthenticated' ;
47+ private readonly basicAuthKeyPrefix = 'Studio:BasicAuth:' ;
4748 private readonly potentiallyAuthenticated : Record < EntityIds , AuthenticatedConnectionKey > ;
4849 private readonly checkedAuthentication : Record < EntityIds , boolean > = { } ;
4950 private readonly allConnections : Record < EntityIds , AuthenticatedConnection > = { } ;
5051
5152 constructor ( ) {
52- this . potentiallyAuthenticated = JSON . parse ( localStorage . getItem ( this . localStorageKey ) || '{}' ) ;
53+ this . potentiallyAuthenticated = JSON . parse ( localStorage . getItem ( this . potentiallyAuthenticatedKey ) || '{}' ) ;
5354 }
5455
5556 public getAllConnections ( ) : Record < EntityIds , AuthenticatedConnection > {
@@ -152,6 +153,19 @@ class AuthStore {
152153 return undefined ;
153154 }
154155
156+ public flagForBasicAuth ( id : EntityIds , credentials : null | { username : string ; password : string ; } ) {
157+ if ( credentials === null ) {
158+ localStorage . removeItem ( this . basicAuthKeyPrefix + id ) ;
159+ } else {
160+ localStorage . setItem ( this . basicAuthKeyPrefix + id , btoa ( JSON . stringify ( credentials ) ) ) ;
161+ }
162+ }
163+
164+ public checkForBasicAuth ( id : EntityIds ) : undefined | { username : string ; password : string ; } {
165+ const value = localStorage . getItem ( this . basicAuthKeyPrefix + id ) ;
166+ return value ? JSON . parse ( atob ( value ) ) : undefined ;
167+ }
168+
155169 public async signOutFromPotentiallyAuthenticatedInstances ( ) {
156170 for ( const entityId in this . potentiallyAuthenticated ) {
157171 this . allConnections [ entityId ] . user = null ;
@@ -162,7 +176,7 @@ class AuthStore {
162176 }
163177 try {
164178 const instanceClient = getInstanceClient ( { id : entityId } ) ;
165- await onInstanceLogoutSubmit ( { instanceClient } ) ;
179+ await onInstanceLogoutSubmit ( { entityId , instanceClient } ) ;
166180 } catch ( err : unknown ) {
167181 console . error ( `Failed to log out from ${ entityId } , carrying on` , err ) ;
168182 }
@@ -202,14 +216,14 @@ class AuthStore {
202216 private flagKeyAsSignedIn ( id : EntityIds , key : AuthenticatedConnectionKey ) {
203217 if ( this . potentiallyAuthenticated [ id ] !== key ) {
204218 this . potentiallyAuthenticated [ id ] = key ;
205- localStorage . setItem ( this . localStorageKey , JSON . stringify ( this . potentiallyAuthenticated ) ) ;
219+ localStorage . setItem ( this . potentiallyAuthenticatedKey , JSON . stringify ( this . potentiallyAuthenticated ) ) ;
206220 }
207221 }
208222
209223 private flagKeyAsSignedOut ( id : EntityIds ) {
210224 if ( this . potentiallyAuthenticated [ id ] ) {
211225 delete this . potentiallyAuthenticated [ id ] ;
212- localStorage . setItem ( this . localStorageKey , JSON . stringify ( this . potentiallyAuthenticated ) ) ;
226+ localStorage . setItem ( this . potentiallyAuthenticatedKey , JSON . stringify ( this . potentiallyAuthenticated ) ) ;
213227 }
214228 }
215229
0 commit comments