窗口不是从NUXT auth-next oauth2scheme.logout()function定义的错误
在我的项目中,我使用nuxt auth-next。为了验证当前保存的cookie,我正在检查NuxtServerinit中的以下条件。
export const actions = {
async nuxtServerInit({ commit }, { app }) {
if (app.$auth.loggedIn) {
const token = app.$auth.strategies.social.token.get()
commit('SET_TOKEN', token)
} else {
await app.$auth.logout('social')
}
},
}
一旦调用此注销方法,就会发生以下错误。 如果我评论此行,“未定义”的错误将消失,
} else {
// await app.$auth.logout('social')
}
但是在我的情况下,如果令牌无效,我想从系统中注销用户。 我的NUXT配置如下,
export default {
loading: '~/components/loaders/Loader.vue',
// Global CSS: https://go.nuxtjs.dev/config-css
css: ['~/assets/css/main.css'],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
'~/plugins/axios.js',
'~/plugins/loader.js',
'~/plugins/vue-tooltip.js',
{
src: '@/plugins/notifications.js',
mode: 'client',
},
{
src: '@/plugins/v-date-picker.js',
mode: 'client',
},
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/eslint
'@nuxtjs/eslint-module',
// https://go.nuxtjs.dev/tailwindcss
'@nuxtjs/tailwindcss',
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios',
'@nuxtjs/auth-next',
'vue-currency-input/nuxt',
],
router: {
// middleware: ['auth', 'servey-middleware', 'routing-middleware'],
middleware: ['auth', 'servey-middleware'],
},
auth: {
redirect: {
login: '/',
callback: '/',
logout: `/`,
home: '/surveys',
},
strategies: {
azureAD: {
scheme: 'oauth2',
endpoints: {
authorization: `${process.env.SIGNIN_POLICY}`,
token: `${process.env.SIGNIN_POLICY}`,
userInfo: '/',
logout: `${process.env.SIGNIN_POLICY}`,
},
token: {
property: 'access_token',
type: 'Bearer',
maxAge: 1800,
},
refreshToken: {
property: 'refresh_token',
maxAge: 60 * 60 * 24 * 30,
},
responseType: 'code',
grantType: 'authorization_code',
redirectUri: `${process.env.REDIRECT_URI}`,
logoutRedirectUri: `${process.env.LOGOUT_URL}`,
clientId: `${process.env.CLIENT_ID}`,
scope: ['openid'],
autoLogout: true,
prompt: 'login',
},
},
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: `${process.env.API_HOST}/api/v1/cont-mgt`,
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
transpile: ['v-date-picker', 'vue-tooltip'],
},
}
这里可能是什么问题或如何解决此问题?
In my project, I use nuxt auth-next. To validate the current saved cookie I'm checking the following conditions in nuxtServerInit.
export const actions = {
async nuxtServerInit({ commit }, { app }) {
if (app.$auth.loggedIn) {
const token = app.$auth.strategies.social.token.get()
commit('SET_TOKEN', token)
} else {
await app.$auth.logout('social')
}
},
}
once this logout method is called, the following error will occur.
"window is not defined" error will be gone if I comment this line,
} else {
// await app.$auth.logout('social')
}
But in my case, I want to log out the user from the system if the token is not valid.
my nuxt configuration is as below,
export default {
loading: '~/components/loaders/Loader.vue',
// Global CSS: https://go.nuxtjs.dev/config-css
css: ['~/assets/css/main.css'],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
'~/plugins/axios.js',
'~/plugins/loader.js',
'~/plugins/vue-tooltip.js',
{
src: '@/plugins/notifications.js',
mode: 'client',
},
{
src: '@/plugins/v-date-picker.js',
mode: 'client',
},
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/eslint
'@nuxtjs/eslint-module',
// https://go.nuxtjs.dev/tailwindcss
'@nuxtjs/tailwindcss',
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios',
'@nuxtjs/auth-next',
'vue-currency-input/nuxt',
],
router: {
// middleware: ['auth', 'servey-middleware', 'routing-middleware'],
middleware: ['auth', 'servey-middleware'],
},
auth: {
redirect: {
login: '/',
callback: '/',
logout: `/`,
home: '/surveys',
},
strategies: {
azureAD: {
scheme: 'oauth2',
endpoints: {
authorization: `${process.env.SIGNIN_POLICY}`,
token: `${process.env.SIGNIN_POLICY}`,
userInfo: '/',
logout: `${process.env.SIGNIN_POLICY}`,
},
token: {
property: 'access_token',
type: 'Bearer',
maxAge: 1800,
},
refreshToken: {
property: 'refresh_token',
maxAge: 60 * 60 * 24 * 30,
},
responseType: 'code',
grantType: 'authorization_code',
redirectUri: `${process.env.REDIRECT_URI}`,
logoutRedirectUri: `${process.env.LOGOUT_URL}`,
clientId: `${process.env.CLIENT_ID}`,
scope: ['openid'],
autoLogout: true,
prompt: 'login',
},
},
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: `${process.env.API_HOST}/api/v1/cont-mgt`,
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
transpile: ['v-date-picker', 'vue-tooltip'],
},
}
What could be wrong here or how can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论