Skip to content

Commit

Permalink
Added missing 'create user' functionality (#27516)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Timvdv authored Jul 29, 2021
1 parent a6e478f commit 282ee8c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/with-passport-and-next-connect/pages/api/user.js
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
Expand Down

0 comments on commit 282ee8c

Please sign in to comment.