vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite
https://vite-pwa-org.netlify.app/
MIT License
3.13k stars 205 forks source link

google auth stopped work with Service Worker #558

Closed Todosiienko closed 1 year ago

Todosiienko commented 1 year ago

Hello. I have SPA project which use Vue3, Vite, Firebase 9, and vite-plugin-pwa to generate Service Worker. Everything worked good but once when i tried to login with Google Auth it started to open the new window with my app without login. When i stop using pwa plugin and unregister previously registered SW i can login with Google without any problems.

My vite.config.js file looks like this

import vue from "@vitejs/plugin-vue";
import legacy from "@vitejs/plugin-legacy";
import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";

import path from "path";
export default defineConfig({
  plugins: [
    vue(),
    legacy({
      targets: ["defaults", "not IE 11"],
    }),
    VitePWA({ strategies: "generateSW", registerType: "autoUpdate" }),
  ],
  server: { port: 8080, host: "localhost" },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  commonjsOptions: {
    esmExternals: true,
  },
  build: {
    minify: "terser",
  },
});

I will very appreciate for any suggestions.

userquin commented 1 year ago

@Todosiienko can you provide a repro or url where I can check it? I don't use PWA with authentication (yet) and never used Firebase.

Todosiienko commented 1 year ago

@userquin I found the reason of this problem. Acording to the firebase docs I have to set up navigation fallback in the VitePWA like this VitePWA({ strategies: "generateSW", registerType: "autoUpdate", workbox:{ navigateFallbackAllowlist:[/^(?!\/__).*/]} }), and now this issue is resolved.

userquin commented 1 year ago

@Todosiienko

can you share the link? https://firebase.google.com/docs/web/pwa seems to have nothing about thisç

EDIT: forgot it, I don't check your comment properly

I want to add some to the PWA docs... (PR welcome ;) )