hanford / next-offline

make your Next.js application work offline using service workers via Google's workbox
https://github.com/hanford/next-offline
1.59k stars 113 forks source link

Retain user login #269

Closed seraj closed 3 years ago

seraj commented 3 years ago

Hi currently, I request backend and got a token, and will be saved to cookie. The issue I'm having is that on the PWA version, the user's auth is breaking every time when you open the app.

what is the best way to manage authentication for PWA's if this is the case?

this is the next.config.js file:

const withOffline = require("next-offline");

const nextConfig = {
    target: process.env.NEXT_TARGET || "serverless",
    transformManifest: (manifest) => ["/"].concat(manifest),
    workboxOpts: {
        swDest: "service-worker.js",
        runtimeCaching: [
            {
                urlPattern: /[.](png|jpg|ico|css)/,
                handler: "CacheFirst",
                options: {
                    cacheName: "assets-cache",
                    cacheableResponse: {
                        statuses: [0, 200],
                    },
                },
            },
            {
                urlPattern: /^https:\/\/code\.getmdl\.io.*/,
                handler: "CacheFirst",
                options: {
                    cacheName: "lib-cache",
                },
            },
            {
                urlPattern: /^http.*/,
                handler: "NetworkFirst",
                options: {
                    cacheName: "http-cache",
                },
            },
        ],
    },
};
module.exports = withOffline(nextConfig);