AuthDecorator#

@palmyralabs/palmyra-wire · lib/palmyra/store/AsyncStore.ts

Overview#

One-method interface for attaching credentials to an outgoing request — Basic auth header, OAuth bearer token, custom cookie, signed URL parameter, etc. Every store reaches its decorator through the shared factory, so a single decorator implementation covers every endpoint in the app.

Interface#

interface AuthDecorator {
  decorate(request: any): void;
}

The request argument is the raw object passed to the underlying axios call — mutate its headers, params, or auth in place.

Example#

import type { AuthDecorator } from '@palmyralabs/palmyra-wire';

// A bearer-token decorator that reads from session storage on every call.
export class BearerTokenDecorator implements AuthDecorator {
  decorate(request: any): void {
    const token = sessionStorage.getItem('access_token');
    if (token) {
      request.headers = { ...(request.headers ?? {}), Authorization: `Bearer ${token}` };
    }
  }
}