Skip to content

Commit

Permalink
Make AUTHDATA fallback from subscriptions to access (#32530)
Browse files Browse the repository at this point in the history
This allows amp-access and amp-subscriptions to coexist
for the purpose of URL substitution. Users of amp-access
can use namespaces to reduce the risk of conflict.
  • Loading branch information
kushal committed Feb 9, 2021
1 parent fcbbe10 commit e255b6e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/service/url-replacements-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,9 @@ export class GlobalVariableSource extends VariableSource {
Services.accessServiceForDocOrNull(element),
Services.subscriptionsServiceForDocOrNull(element),
]).then((services) => {
const service = /** @type {?../../extensions/amp-access/0.1/access-vars.AccessVars} */ (services[0] ||
services[1]);
const accessService = /** @type {?../../extensions/amp-access/0.1/access-vars.AccessVars} */ (services[0]);
const subscriptionService = /** @type {?../../extensions/amp-access/0.1/access-vars.AccessVars} */ (services[1]);
const service = accessService || subscriptionService;
if (!service) {
// Access/subscriptions service is not installed.
user().error(
Expand All @@ -650,6 +651,13 @@ export class GlobalVariableSource extends VariableSource {
);
return null;
}

// If both an access and subscription service are present, prefer
// subscription then fall back to access because access can be namespaced.
if (accessService && subscriptionService) {
return getter(subscriptionService) || getter(accessService);
}

return getter(service);
});
}
Expand Down

0 comments on commit e255b6e

Please sign in to comment.