Skip to content

Instantly share code, notes, and snippets.

@cpv123
Last active January 4, 2022 13:06
Show Gist options
  • Save cpv123/8417976b726331f1b35c81c76574d6aa to your computer and use it in GitHub Desktop.
Save cpv123/8417976b726331f1b35c81c76574d6aa to your computer and use it in GitHub Desktop.
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