From 5a4fc96ebcd949283ede68541c74ef8e0c4f3558 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 12 Oct 2022 13:11:44 -0700 Subject: [PATCH] Refactor API authentication. --- components/forms/AccountEditForm.js | 8 +++---- components/forms/WebsiteEditForm.js | 4 ++-- lib/auth.js | 26 ++++++++++---------- pages/api/accounts/[id]/index.js | 24 +++++++++---------- pages/api/websites/[id]/active.js | 7 +++--- pages/api/websites/[id]/events.js | 7 +++--- pages/api/websites/[id]/index.js | 33 +++++++++++--------------- pages/api/websites/[id]/metrics.js | 7 +++--- pages/api/websites/[id]/pageviews.js | 7 +++--- pages/api/websites/[id]/reset.js | 4 ++++ pages/api/websites/[id]/stats.js | 7 +++--- pages/api/websites/index.js | 4 ++-- queries/admin/account/updateAccount.js | 6 ++--- 13 files changed, 71 insertions(+), 73 deletions(-) diff --git a/components/forms/AccountEditForm.js b/components/forms/AccountEditForm.js index 3f54b2f5..70125656 100644 --- a/components/forms/AccountEditForm.js +++ b/components/forms/AccountEditForm.js @@ -15,13 +15,13 @@ const initialValues = { password: '', }; -const validate = ({ userId, username, password }) => { +const validate = ({ id, username, password }) => { const errors = {}; if (!username) { errors.username = ; } - if (!userId && !password) { + if (!id && !password) { errors.password = ; } @@ -33,8 +33,8 @@ export default function AccountEditForm({ values, onSave, onClose }) { const [message, setMessage] = useState(); const handleSubmit = async values => { - const { userId } = values; - const { ok, data } = await post(userId ? `/accounts/${userId}` : '/accounts', values); + const { id } = values; + const { ok, data } = await post(id ? `/accounts/${id}` : '/accounts', values); if (ok) { onSave(); diff --git a/components/forms/WebsiteEditForm.js b/components/forms/WebsiteEditForm.js index 00cba540..b56e21c1 100644 --- a/components/forms/WebsiteEditForm.js +++ b/components/forms/WebsiteEditForm.js @@ -94,7 +94,7 @@ export default function WebsiteEditForm({ values, onSave, onClose }) { return ( @@ -128,7 +128,7 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {