From 1c3d5b25565b29cdb17809fbacf6c2cac40213e8 Mon Sep 17 00:00:00 2001
From: Zeeland <287017217@qq.com>
Date: Tue, 25 Oct 2022 16:05:25 +0800
Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Nickname=20are=20not?=
=?UTF-8?q?=20rendered=20in=20html=20style=20when=20searching=20for=20user?=
=?UTF-8?q?s.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/common/user/list.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/common/user/list.vue b/components/common/user/list.vue
index 816fd51..94f2903 100644
--- a/components/common/user/list.vue
+++ b/components/common/user/list.vue
@@ -10,7 +10,7 @@
- {{ user.nickname }}
+
From 9fc6e642b17ef07d7408b4158eb323205051c004 Mon Sep 17 00:00:00 2001
From: NewVo1d
Date: Thu, 27 Oct 2022 23:15:01 +0800
Subject: [PATCH 2/5] fix: corrected a grammatical error
---
pages/login.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pages/login.vue b/pages/login.vue
index d0cd43f..fb8cc35 100644
--- a/pages/login.vue
+++ b/pages/login.vue
@@ -123,7 +123,7 @@ export default {
})
}
}
- },functions(error) {
+ },function(error) {
_ts.$set(_ts, 'loginLoading', false);
})
} else {
From a2f72f6d0a42db7ac1cef06627dde93fd19aab66 Mon Sep 17 00:00:00 2001
From: ronger
Date: Thu, 27 Oct 2022 23:22:46 +0800
Subject: [PATCH 3/5] :sparkles: nuxt/auth
---
components/common/user/list.vue | 2 +-
components/layouts/mobile/header.vue | 341 +-
components/layouts/pc/header.vue | 414 +-
middleware/authenticated.js | 6 -
middleware/notAuthenticated.js | 6 -
nuxt.config.js | 39 +-
package.json | 3 +-
pages/admin.vue | 3 +-
pages/admin/articles.vue | 1 +
pages/admin/bank-accounts.vue | 1 +
pages/admin/banks.vue | 1 +
pages/admin/comments.vue | 1 +
pages/admin/currency-rules.vue | 1 +
pages/admin/dashboard.vue | 1 +
pages/admin/products.vue | 1 +
pages/admin/roles.vue | 1 +
pages/admin/tag/post/_tag_id.vue | 1 +
pages/admin/tags.vue | 1 +
pages/admin/topic/_topic_uri.vue | 3 +-
pages/admin/topic/bind/_topic_id.vue | 1 +
pages/admin/topic/post/_topic_id.vue | 1 +
pages/admin/topics.vue | 1 +
pages/admin/users.vue | 1 +
pages/answer.vue | 1 +
pages/article/_article_id.vue | 11 +-
pages/article/post/_article_id.vue | 5 +-
pages/chats/_account.vue | 2 +-
pages/draft/_draft_id.vue | 9 +-
pages/drafts.vue | 3 +-
pages/login.vue | 42 +-
pages/notification.vue | 4 +-
pages/portfolio/_portfolio_id.vue | 6 +-
pages/portfolio/manager/_portfolio_id.vue | 2 +-
pages/portfolio/post/_portfolio_id.vue | 4 +-
pages/user/_account.vue | 12 +-
pages/user/settings.vue | 3 +-
pages/user/settings/account.vue | 3 +-
pages/user/settings/avatar.vue | 3 +-
pages/user/settings/login-record.vue | 3 +-
pages/user/settings/security.vue | 2 +-
pages/wallet.vue | 35 +-
plugins/axios.js | 16 +-
store/draft.js | 1 -
store/index.js | 62 -
store/wallet.js | 5 +-
yarn.lock | 13913 ++++++++++----------
46 files changed, 7378 insertions(+), 7600 deletions(-)
delete mode 100644 middleware/authenticated.js
delete mode 100644 middleware/notAuthenticated.js
diff --git a/components/common/user/list.vue b/components/common/user/list.vue
index 816fd51..194a9de 100644
--- a/components/common/user/list.vue
+++ b/components/common/user/list.vue
@@ -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 @@
-
+