如何在Next.js中使用Google Workbox?

问题描述 投票:2回答:1

我有一个Next.js应用程序,目前正在使用sw-precache和sw-precache-webpack-plugin来生成服务工作者。

我想迁移使用Google Workbox和workbox-webpack-plugin。有人在Next.js上下文中成功完成了吗?

service-worker nextjs workbox
1个回答
0
投票

我认为你最好的选择是使用cookies,让他们在服务器端使用像https://github.com/matthewmueller/next-cookies这样的东西

或者在客户端的服务器和cookie-js节点模块中使用req.headers.cookie,如教程中所示:https://fullstack-developer.academy/using-next-js-and-auth0/

您可以使用以下教程中的代码找到一个repo:https://github.com/tpiros/nextjs-auth0/blob/master/static/auth.js

看一下getTokenForBrowser和getTokenForServer函数。

© www.soinside.com 2019 - 2024. All rights reserved.