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