From 282ee8c9d0af8587873855793d873593e18278c4 Mon Sep 17 00:00:00 2001 From: Tim van de Vathorst Date: Fri, 30 Jul 2021 00:16:55 +0200 Subject: [PATCH] Added missing 'create user' functionality (#27516) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I was trying to run the demo locally and found out that the create user function was missing, so I added it! ## Documentation / Examples - [ ✔ ] Make sure the linting passes --- examples/with-passport-and-next-connect/pages/api/user.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/with-passport-and-next-connect/pages/api/user.js b/examples/with-passport-and-next-connect/pages/api/user.js index 05f97a30ce28b..726edabd1cf15 100644 --- a/examples/with-passport-and-next-connect/pages/api/user.js +++ b/examples/with-passport-and-next-connect/pages/api/user.js @@ -1,6 +1,6 @@ import nextConnect from 'next-connect' import auth from '../../middleware/auth' -import { deleteUser, updateUserByUsername } from '../../lib/db' +import { deleteUser, createUser, updateUserByUsername } from '../../lib/db' const handler = nextConnect() @@ -13,6 +13,11 @@ handler // res.json({ user: { name, username, favoriteColor } }) res.json({ user: req.user }) }) + .post((req, res) => { + const { username, password, name } = req.body + createUser(req, { username, password, name }) + res.status(200).json({ success: true, message: 'created new user' }) + }) .use((req, res, next) => { // handlers after this (PUT, DELETE) all require an authenticated user // This middleware to check if user is authenticated before continuing