Monday, December 18, 2017

Service worker and authentication in a Polymer app

In order to sign in with a Google account or to sign out, a web app running on Google App Engine needs to navigate to a URIs that start with /_ah.  If the app is configured to use a service worker, the service worker will intercept these URIs and won't allow the sign-in/sign-out flow to continue.

In order to enable sign-in/sign-out for a Polymer app, polymer.json configuration needs to specify swPrecacheConfig option, e.g.:

"builds": [
  {
    "preset": "es6-unbundled",
    "swPrecacheConfig": "sw-precache-config.js"
  }

And sw-precache-config.js file needs to specify navigateFallbackWhitelist option:

module.exports = {
    // Everything except '/_' prefixes
    navigateFallbackWhitelist: [/^(?!\/_).*/]
};

When built with these options, the generated service worker will allow a Polymer app to successfully navigate to sign-in/sign-out URIs.

See Generating a Service Worker for more information.

No comments:

Post a Comment