BasicAuthProvider#
@palmyralabs/palmyra-wire · lib/palmyra/store/auth/AuthProviders.ts
Overview#
HTTP Basic authentication decorator — stub. The class is declared with username / password fields and a decorate(request) method, but the current implementation does not populate the Authorization header. Treat it as a placeholder for upstream work.
If you need Basic auth today, implement AuthDecorator directly (see the example at the bottom of this page).
Source#
class BasicAuthProvider implements AuthDecorator {
username: string;
password: string;
BasicAuthProvider(username: string, password: string) { // NB: not a TS constructor
this.username = username;
this.password = password;
}
decorate(request: any): void { }
}
export { BasicAuthProvider };Known limitations#
- No real constructor.
BasicAuthProvider(username, password)is declared as a named method, notconstructor(username, password).new BasicAuthProvider('u', 'p')in TypeScript does not assign the fields — you get an instance whoseusername/passwordareundefined. decorate()is empty. Even with populated fields, the method doesn’t attach anAuthorizationheader today.
Workaround — roll your own decorator#
import type { AuthDecorator } from '@palmyralabs/palmyra-wire';
export class BasicAuth implements AuthDecorator {
constructor(private readonly username: string, private readonly password: string) {}
decorate(request: any): void {
const token = btoa(`${this.username}:${this.password}`);
request.headers = { ...(request.headers ?? {}), Authorization: `Basic ${token}` };
}
}Wire it through a custom factory wrapper, or install it as an axios interceptor via StoreOptions.axiosCustomizer (see PalmyraStoreFactory).