Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practices for Next steps, please #2038

Open
francisrod01 opened this issue May 29, 2022 · 0 comments
Open

Best practices for Next steps, please #2038

francisrod01 opened this issue May 29, 2022 · 0 comments

Comments

@francisrod01
Copy link

francisrod01 commented May 29, 2022

Opinion: We should have a Discussions tab here.

I want to scale this repo to my side projects, and maybe use it for professional ones, so how are the plans for best practices?

I'm implementing a dashboard route in the backend, but I wonder if the login function shouldn't be a middleware, like the requireAdmin.

I just implemented a dashboard.route.js to get all users registered, but it seems unsafe because there's no JWT verification in it.

const express = require('express');
const asyncHandler = require('express-async-handler');
const requireAdmin = require('../middleware/require-admin');
const userCtrl = require('../controllers/user.controller');

const router = express.Router();
module.exports = router;

router.get('/user', asyncHandler(getUsers), requireAdmin);

async function getUsers(req, res) {
  let users = await userCtrl.retrieve();

  users = users.map((user) => {
    user = user.toObject();
    delete user.hashedPassword;

    return user;
  });

  res.json(users);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant