Skip to main content

OrderByCodeAccessStrategy

OrderByCodeAccessStrategy

The OrderByCodeAccessStrategy determines how access to a placed Order via the orderByCode query is granted. With a custom strategy anonymous access could be made permanent or tied to specific conditions like IP range or an Order status.

Example

This example grants access to the requested Order to anyone – unless it's Monday.

export class NotMondayOrderByCodeAccessStrategy implements OrderByCodeAccessStrategy {
canAccessOrder(ctx: RequestContext, order: Order): boolean {
const MONDAY = 1;
const today = (new Date()).getDay();

return today !== MONDAY;
}
}
info

This is configured via the orderOptions.orderByCodeAccessStrategy property of your VendureConfig.

Signature
interface OrderByCodeAccessStrategy extends InjectableStrategy {
canAccessOrder(ctx: RequestContext, order: Order): boolean | Promise<boolean>;
}

canAccessOrder

method
(ctx: RequestContext, order: Order) => boolean | Promise<boolean>

Gives or denies permission to access the requested Order

DefaultOrderByCodeAccessStrategy

The default OrderByCodeAccessStrategy used by Vendure. It permitts permanent access to the Customer owning the Order and anyone within a given time period after placing the Order (defaults to 2h).

Signature
class DefaultOrderByCodeAccessStrategy implements OrderByCodeAccessStrategy {
constructor(anonymousAccessDuration: string)
canAccessOrder(ctx: RequestContext, order: Order) => boolean;
}

constructor

method
(anonymousAccessDuration: string) => DefaultOrderByCodeAccessStrategy

canAccessOrder

method
(ctx: RequestContext, order: Order) => boolean