如何实现Nuxt Server Middleware Google授权?

How to implement Nuxt Server Middleware Google authorization?

我的 nuxt.config.js

中有以下身份验证配置
auth: {
  strategies: {
    google: {
      client_id: process.env.GOOGLE_KEY,
      codeChallengeMethod: '',
      scope: ['profile', 'email'],
      responseType: 'token id_token'
    }
  },
  redirect: {
    login: '/login',
    logout: '/logout',
    home: '/',
    callback: '/welcome'
  },
  rewriteRedirects: false
},
router: {
  middleware: ['auth']
},
serverMiddleware: [
  { path: '/db', handler: '~/api/db.js' },
],

这会设置前端身份验证,因此我的所有 .vue 页面都受到保护。除此之外,我还有一些 serverMiddleware,就像我的 api/db.js

const app = require('express')()

app.get('/fields/:schema', async (req, res) => {
  var result = []
  // some logics here
  return result;
})

对该资源的请求不受任何授权保护,但我注意到在浏览器的网络选项卡中,$axios.$get('db/fields/some_schema') 从我的 .vue 页面发出的所有请求都设置了一些 Google 饼干,喜欢

auth.strategy=google; auth._token.google=Bearer...

我的 serverMiddleware 中没有使用它 api/db.js

Nuxt.js 是否有一些开箱即用的方法来为服务器中间件设置 Google 身份验证?正确的设置方法是什么?

我不得不使用这个 nuxt 配置

  auth: {
 strategies: {
   google: {
    clientId: 'to be added',
    clientId: '<your cliendID here>',
    codeChallengeMethod: '',
    responseType: 'code',
    endpoints: {
      token: 'http://localhost:8000/social-login/google/',
      userInfo: 'http://localhost:8000/auth/user/'
    },
   },
 }
},

并实施后端令牌和 userInfo 端点