From 9fd711c04bfb952b3e78fd74e02ca10e5d6627e4 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Thu, 15 Oct 2020 20:55:24 +0200 Subject: [PATCH] #54 user accounts - admin panel --- .env.dist | 1 - components/Account.vue | 6 ++---- components/NounSubmitForm.vue | 9 +++------ nuxt.config.js | 1 - plugins/auth.js | 3 +++ routes/nouns.vue | 23 +++++++++++------------ server/authenticate.js | 9 +++++++++ server/nouns.js | 24 +++++++++++------------- server/user.js | 18 +++++------------- 9 files changed, 44 insertions(+), 50 deletions(-) create mode 100644 server/authenticate.js diff --git a/.env.dist b/.env.dist index 22a6833bc..4b437848f 100644 --- a/.env.dist +++ b/.env.dist @@ -1,5 +1,4 @@ BASE_URL=http://localhost:3000 -SECRET=secret MAILER_HOST= MAILER_PORT= diff --git a/components/Account.vue b/components/Account.vue index ad8c67ee9..e65232ff0 100644 --- a/components/Account.vue +++ b/components/Account.vue @@ -20,7 +20,7 @@

{{ email }}

-

+

user.account.admin

@@ -45,9 +45,7 @@ async changeUsername() { await this.post(`/user/change-username`, { username: this.username - }, { - headers: {...this.$auth()}, - }); + }, { headers: this.$auth() }); }, async post(url, data, options = {}) { this.error = ''; diff --git a/components/NounSubmitForm.vue b/components/NounSubmitForm.vue index 6db6d1d37..8e0323c19 100644 --- a/components/NounSubmitForm.vue +++ b/components/NounSubmitForm.vue @@ -32,7 +32,7 @@ nouns.neuter nouns.neuterShort - + @@ -118,9 +118,6 @@ import { nounTemplates } from '../src/data'; export default { - props: { - secret: {}, - }, data() { return { form: { @@ -142,9 +139,9 @@ methods: { async submit(event) { this.submitting = true; - await this.$axios.$post(`/nouns/submit?secret=${this.secret}`, { + await this.$axios.$post(`/nouns/submit`, { data: this.form, - }); + }, { headers: this.$auth() }); this.submitting = false; this.afterSubmit = true; diff --git a/nuxt.config.js b/nuxt.config.js index 00b377267..5c5639623 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -86,7 +86,6 @@ export default { }, env: { BASE_URL: process.env.BASE_URL, - SECRET: process.env.SECRET, PUBLIC_KEY: fs.readFileSync(__dirname + '/keys/public.pem').toString(), }, serverMiddleware: { diff --git a/plugins/auth.js b/plugins/auth.js index 0cfe87871..53b6ee79c 100644 --- a/plugins/auth.js +++ b/plugins/auth.js @@ -16,4 +16,7 @@ export default ({app, store}) => { authorization: 'Bearer ' + store.state.token, } : {}; }; + Vue.prototype.$admin = _ => { + return store.state.user && store.state.user.authenticated && store.state.user.roles === 'admin'; + }; } diff --git a/routes/nouns.vue b/routes/nouns.vue index 97b09a760..b98422f8e 100644 --- a/routes/nouns.vue +++ b/routes/nouns.vue @@ -14,7 +14,7 @@ -
+
{{ nounsCountApproved() }} nouns.approved, {{ nounsCountPending() }} nouns.pending. @@ -44,7 +44,7 @@
- +
- + @@ -83,7 +83,7 @@ - @@ -128,7 +128,7 @@ -
@@ -59,7 +59,7 @@ nouns.neuter
+