Last active
January 4, 2022 13:06
-
-
Save cpv123/8417976b726331f1b35c81c76574d6aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connectToDatabase } from 'utils/db'; | |
import { withAuth } from 'utils/auth'; | |
import User from 'utils/db/user'; | |
const handler = async (req, res) => { | |
// Ensure that we're connected to the database | |
await assertDBConnection() | |
// Find all users and return them as JSON | |
const users = await User.find({}) | |
res.json({ users }) | |
}) | |
// Use "middleware" to check for authentication | |
export default withAuth(handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment