Laravel PWA-会话已过期

时间:2018-11-08 17:55:13

标签: javascript laravel service-worker progressive-web-apps

因此,我在最新的Laravel 5.7中构建了一个Web应用程序,并且运行良好,

直到我尝试将其转换为PWA(渐进式Web应用程序)。

我是用sw-precache-webpack-plugin做的
这是实现:

mix.webpackConfig({
 plugins: [
    new SWPrecacheWebpackPlugin({
      filename: 'service-worker.js',      
      cacheId: 'pwa',
      staticFileGlobs: ['public/**/*.{css,eot,svg,ttf,woff,woff2,js,html,png,jpg}'],
      minify: true,
      stripPrefix: 'public/',
      handleFetch: true,
      ignoreUrlParametersMatching: [/login/,/register/,/^utm_/],
      dynamicUrlToDependencies: {
        '/login':            ['resources/views/auth/login.blade.php'],
        '/register':         ['resources/views/auth/register.blade.php'],
        '/password/reset':   ['resources/views/auth/passwords/email.blade.php'],        
        '/':                 ['resources/views/index.blade.php'],
        '/dream-journal':    ['resources/views/dream-journal.blade.php'],
        '/techniques':       ['resources/views/techniques.blade.php'],
        '/community':        ['resources/views/community.blade.php'],
        '/profile':          ['resources/views/profile.blade.php'],        
        '/settings':         ['resources/views/settings.blade.php']
      },
      staticFileGlobsIgnorePatterns: [/\.map$/, /mix-manifest\.json$/, /manifest\.json$/, /service-worker\.js$/],
      navigateFallback: '/',
      runtimeCaching: [
        {
          urlPattern: /^https:\/\/fonts\.googleapis\.com\//,
          handler: 'cacheFirst'
        },
        {
          urlPattern: /^https:\/\/www\.thecocktaildb\.com\/images\/media\/drink\/(\w+)\.jpg/,
          handler: 'cacheFirst'
        }
      ],
      // importScripts: ['./js/push_message.js']
    })
  ]
});

我还添加了完整的manifest.json文件,因此对于'/','/ login'和'/ register'路由(不需要身份验证)-Service Worker实际上已经注册并且可以正确缓存。

到目前为止,一切都很完美。
问题是-现在当我进入/ login或/ register表单并提交它时,Laravel抛出

419 Sorry, your session has expired. Please refresh and try again.

请帮助我,我正在努力解决数天...

1 个答案:

答案 0 :(得分:0)

注销操作是一个表单发布。将 csrf 键(刀片中的 @csrf)添加到您的注销表单中。