diff --git a/components/common/user/list.vue b/components/common/user/list.vue
index 816fd51..07a39a3 100644
--- a/components/common/user/list.vue
+++ b/components/common/user/list.vue
@@ -10,7 +10,7 @@
- {{ user.nickname }}
+
@@ -48,7 +48,7 @@ export default {
name: "UserList",
computed: {
...mapState({
- userInfo: state => state.oauth
+ userInfo: state => state.auth.user
})
},
props: {
diff --git a/components/layouts/mobile/header.vue b/components/layouts/mobile/header.vue
index a4a13e8..377d78e 100644
--- a/components/layouts/mobile/header.vue
+++ b/components/layouts/mobile/header.vue
@@ -9,7 +9,7 @@
-
首页
专题
@@ -19,8 +19,9 @@
-
- 发帖
+
+ 发帖
@@ -37,15 +38,17 @@
-
+
-
+
- {{ nickname }}
+
+ {{ user.nickname }}
+
系统管理
资料与账号
@@ -70,203 +73,165 @@
diff --git a/components/layouts/pc/header.vue b/components/layouts/pc/header.vue
index 39b4e15..5a1bc39 100644
--- a/components/layouts/pc/header.vue
+++ b/components/layouts/pc/header.vue
@@ -20,7 +20,7 @@
-
+
-
+
-
+
- {{ nickname }}
+ {{ user.nickname }}
个人中心
@@ -138,251 +138,213 @@
diff --git a/middleware/authenticated.js b/middleware/authenticated.js
deleted file mode 100644
index 22e4512..0000000
--- a/middleware/authenticated.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export default function ({ store, redirect }) {
- // If the user is not authenticated
- if (!store.state.oauth) {
- return redirect('/login')
- }
-}
diff --git a/middleware/notAuthenticated.js b/middleware/notAuthenticated.js
deleted file mode 100644
index 624fd92..0000000
--- a/middleware/notAuthenticated.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export default function ({ store, redirect }) {
- // If the user is authenticated redirect to home page
- if (store.state.oauth) {
- return redirect('/')
- }
-}
diff --git a/nuxt.config.js b/nuxt.config.js
index 17f4ab4..f23eb4f 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -70,9 +70,44 @@ export default {
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy',
- 'js-cookie',
- 'cookieparser'
+ '@nuxtjs/auth-next'
],
+ auth: {
+ redirect: {
+ login: '/login',
+ logout: false,
+ home: false
+ },
+ strategies: {
+ local: {
+ // scope: true,
+ scheme: 'refresh',
+ token: {
+ property: 'token',
+ global: true,
+ maxAge: 60 * 15,
+ // required: true,
+ type: false
+ },
+ refreshToken: {
+ property: 'refreshToken',
+ data: 'refreshToken',
+ maxAge: 60 * 60 * 2
+ },
+ user: {
+ property: 'user',
+ autoFetch: false
+ },
+ endpoints: {
+ login: { url: '/api/auth/login', method: 'post' },
+ logout: { url: '/api/auth/logout', method: 'post' },
+ refresh: { url: '/api/auth/refresh-token', method: 'post' },
+ user: { url: '/api/auth/user', method: 'get' }
+ },
+ autoLogout: false
+ }
+ }
+ },
axios: {
proxy: true // 开启proxy
},
diff --git a/package.json b/package.json
index 8b6f0dd..ab3b621 100644
--- a/package.json
+++ b/package.json
@@ -11,13 +11,12 @@
},
"dependencies": {
"@chenfengyuan/vue-qrcode": "^1.0.2",
+ "@nuxtjs/auth-next": "^5.0.0-1648802546.c9880dc",
"@nuxtjs/axios": "^5.13.1",
"babel-plugin-lodash": "^3.3.4",
- "cookieparser": "^0.1.0",
"echarts": "^4.9.0",
"element-ui": "^2.15.8",
"express": "^4.18.1",
- "js-cookie": "^2.2.1",
"lodash": "^4.17.21",
"net": "^1.0.2",
"nuxt": "^2.15.8",
diff --git a/pages/admin.vue b/pages/admin.vue
index 4df8de0..e968c88 100644
--- a/pages/admin.vue
+++ b/pages/admin.vue
@@ -45,6 +45,7 @@ import _ from 'lodash'
export default {
name: "Admin",
+ middleware: 'auth',
data() {
return {
menus: [
@@ -144,7 +145,7 @@ export default {
return this.$store.state.activeMenu;
},
hasPermissions() {
- return this.$store.getters.hasPermissions('blog_admin');
+ return this.$auth.hasScope('admin') || this.$auth.hasScope('blog_admin');
}
},
methods: {
diff --git a/pages/admin/articles.vue b/pages/admin/articles.vue
index d21a11a..bb5b231 100644
--- a/pages/admin/articles.vue
+++ b/pages/admin/articles.vue
@@ -107,6 +107,7 @@ import EditTags from '~/components/widget/tags';
export default {
name: "articles",
+ middleware: 'auth',
components: {
EditTags
},
diff --git a/pages/admin/bank-accounts.vue b/pages/admin/bank-accounts.vue
index bd91284..0059f7b 100644
--- a/pages/admin/bank-accounts.vue
+++ b/pages/admin/bank-accounts.vue
@@ -75,6 +75,7 @@ import Records from "../../components/common/bank/account/records";
export default {
name: "bank-accounts",
+ middleware: 'auth',
components: {Records},
fetch() {
let {store, params, error} = this.$nuxt.context
diff --git a/pages/admin/banks.vue b/pages/admin/banks.vue
index 4e53bff..ce2f04a 100644
--- a/pages/admin/banks.vue
+++ b/pages/admin/banks.vue
@@ -87,6 +87,7 @@ import {mapState} from 'vuex';
export default {
name: "banks",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/comments.vue b/pages/admin/comments.vue
index db406d0..8a50fec 100644
--- a/pages/admin/comments.vue
+++ b/pages/admin/comments.vue
@@ -97,6 +97,7 @@ import {mapState} from 'vuex';
export default {
name: "comments",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/currency-rules.vue b/pages/admin/currency-rules.vue
index 546923f..63e0e45 100644
--- a/pages/admin/currency-rules.vue
+++ b/pages/admin/currency-rules.vue
@@ -81,6 +81,7 @@ import {mapState} from 'vuex';
export default {
name: "currency-rules",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/dashboard.vue b/pages/admin/dashboard.vue
index e007989..5228568 100644
--- a/pages/admin/dashboard.vue
+++ b/pages/admin/dashboard.vue
@@ -248,6 +248,7 @@ import EditTags from '~/components/widget/tags';
Vue.prototype.$echarts = echarts;
export default {
name: "Dashboard",
+ middleware: 'auth',
components: {
EditTags
},
diff --git a/pages/admin/products.vue b/pages/admin/products.vue
index c586118..8469984 100644
--- a/pages/admin/products.vue
+++ b/pages/admin/products.vue
@@ -80,6 +80,7 @@ import {mapState} from 'vuex';
export default {
name: "products",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/roles.vue b/pages/admin/roles.vue
index 2d2d40b..be0093a 100644
--- a/pages/admin/roles.vue
+++ b/pages/admin/roles.vue
@@ -91,6 +91,7 @@
export default {
name: "roles",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/tag/post/_tag_id.vue b/pages/admin/tag/post/_tag_id.vue
index 6356ed9..1da85b2 100644
--- a/pages/admin/tag/post/_tag_id.vue
+++ b/pages/admin/tag/post/_tag_id.vue
@@ -126,6 +126,7 @@ import apiConfig from '~/config/api.config';
export default {
name: "PostTag",
+ middleware: 'auth',
components: {
VueCropper
},
diff --git a/pages/admin/tags.vue b/pages/admin/tags.vue
index 96e9996..4e5ee15 100644
--- a/pages/admin/tags.vue
+++ b/pages/admin/tags.vue
@@ -48,6 +48,7 @@
export default {
name: "tags",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/topic/_topic_uri.vue b/pages/admin/topic/_topic_uri.vue
index 30f7e89..5ffbbd3 100644
--- a/pages/admin/topic/_topic_uri.vue
+++ b/pages/admin/topic/_topic_uri.vue
@@ -71,6 +71,7 @@ import {mapState} from 'vuex';
export default {
name: "adminTopicDetail",
+ middleware: 'auth',
validate({params, store}) {
if (typeof params.topic_uri === 'undefined') {
return true;
@@ -94,7 +95,7 @@ export default {
tags: state => state.topic.tags.data
}),
hasPermissions() {
- return this.$store.getters.hasPermissions('topic');
+ return this.$auth.hasScope('topic');
}
},
methods: {
diff --git a/pages/admin/topic/bind/_topic_id.vue b/pages/admin/topic/bind/_topic_id.vue
index ceec887..3d34064 100644
--- a/pages/admin/topic/bind/_topic_id.vue
+++ b/pages/admin/topic/bind/_topic_id.vue
@@ -53,6 +53,7 @@ import {mapState} from 'vuex';
export default {
name: "adminTopicBindTag",
+ middleware: 'auth',
fetch({store, params, error}) {
let _ts = this;
return Promise.all([
diff --git a/pages/admin/topic/post/_topic_id.vue b/pages/admin/topic/post/_topic_id.vue
index a92434f..e3f186e 100644
--- a/pages/admin/topic/post/_topic_id.vue
+++ b/pages/admin/topic/post/_topic_id.vue
@@ -124,6 +124,7 @@ import apiConfig from '~/config/api.config';
export default {
name: "adminTopicPost",
+ middleware: 'auth',
components: {
VueCropper
},
diff --git a/pages/admin/topics.vue b/pages/admin/topics.vue
index 347a5a2..2b864b4 100644
--- a/pages/admin/topics.vue
+++ b/pages/admin/topics.vue
@@ -39,6 +39,7 @@
export default {
name: "topics",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/admin/users.vue b/pages/admin/users.vue
index 0f9cb1f..e740506 100644
--- a/pages/admin/users.vue
+++ b/pages/admin/users.vue
@@ -119,6 +119,7 @@ import {mapState} from 'vuex';
export default {
name: "users",
+ middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
diff --git a/pages/answer.vue b/pages/answer.vue
index aafc324..6dec761 100644
--- a/pages/answer.vue
+++ b/pages/answer.vue
@@ -62,6 +62,7 @@ import {mapState} from 'vuex';
export default {
name: "answer",
+ middleware: 'auth',
fetch({store, params, error}) {
return Promise.all([
store
diff --git a/pages/article/_article_id.vue b/pages/article/_article_id.vue
index 1c6840a..a3d7ee1 100644
--- a/pages/article/_article_id.vue
+++ b/pages/article/_article_id.vue
@@ -82,7 +82,7 @@
-
+