User and authentication models

Well defined user and authentication models built using mongoose. Easily extend and create new models to support your app.

Model

    const updateUserById = async (userId, updateBody) => {
      const user = await getUserById(userId);
      if (!user) {
        throw new ApiError(httpStatus.NOT_FOUND, 'User not found');
      }
      if (updateBody.email && (await User.isEmailTaken(updateBody.email, userId))) {
        throw new ApiError(httpStatus.BAD_REQUEST, 'Email already taken');
      }
      Object.assign(user, updateBody);
      await user.save();
      return user;
    };
                    

React js and Tailwind CSS components

Pre-built collection of components: forms, buttons, modals and much more. Use these components to build UI in an easy and modular fashion.

View

    import React from "react";
    import SimpleModal from "components/Modals/SimpleModal.js";

    export default function DeleteUserModal({open, callback}) {
      return (
        <SimpleModal open={open}
          title="Delete User"
          neg_text="Cancel" 
          pos_text="Delete User"
          callback={callback}
          body={<p className="my-4 text-gray-600 leading-relaxed">Are you sure you want to delete this user?</p>} />
      );
    }
                    

Route specific controllers with centralized error handling

Well designed controllers help easy navigation of code and avoid bugs.

Controller

    const createUser = catchAsync(async (req, res) => {
      const { name, email } = req.body
      const stripeUser = await stripeService.createCustomer(name, email);
      req.body.stripeId = stripeUser.id;
      const user = await userService.createUser(req.body);
      res.status(httpStatus.CREATED).send(user);
    });