├── .env.example
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── components
├── CustomerContext.jsx
├── UserContext.jsx
└── layout.jsx
├── lib
└── redirectTo.js
├── middlewares
├── authentication.js
├── database.js
├── middleware.js
└── session.js
├── next.config.js
├── now.json
├── package.json
├── pages
├── _app.jsx
├── api
│ ├── authenticate.js
│ ├── customer.js
│ ├── customer
│ │ └── [id].js
│ ├── session.js
│ ├── user
│ │ ├── index.js
│ │ └── profilepicture.js
│ └── users.js
├── customer
│ ├── customerForm.jsx
│ ├── index.jsx
│ └── listData.jsx
├── index.jsx
├── login.jsx
├── profile
│ ├── index.jsx
│ └── settings.jsx
└── signup.jsx
└── utils
└── auth.js
/.env.example:
--------------------------------------------------------------------------------
1 | # MONGODB_URI=
2 | # DB_NAME=
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | # package-lock
64 | package-lock.json
65 | yarn.lock
66 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contribute to nextjs-mongodb-app
2 |
3 | :+1::tada: Thank you for being here. It is people like you that make `nextjs-mongodb-app` great and help shape a better open-source community.
4 |
5 | Following this guideline improves communication and organization, which helps save your and other developers' times and effort in future development.
6 |
7 | ## What `nextjs-mongodb-app` is looking for
8 |
9 | I welcome all contributions from the community. There are many ways to contribute:
10 |
11 | - :art: Submit PR to fix bugs, enhance/add existed/new features.
12 | - :children_crossing: Submit bug reports and feature requests.
13 | - :pencil: Improve documentation and writing examples.
14 |
15 | However, please avoid using the issue tracker for support questions. You can receive help on my [Spectrum community](https://spectrum.chat/luvbitstudio).
16 |
17 | ## How to contribute
18 |
19 | ### Bug reports
20 |
21 | If you are submitting a :bug: bug report, please:
22 | - Use a clear and descriptive title. Describe the behavior you observed and the expected behavior.
23 | - Describe the exact steps which reproduce the problem. A minimal reproduction repo is greatly appreciated.
24 | - Include Node version, OS, or other information that may be helpful in the troubleshooting.
25 |
26 | ### Process on submitting a PR
27 |
28 | *Generally, all pull requests should have references to an issue.*
29 |
30 | If you are :sparkles: **adding a new feature** or :zap: **improving an algorithm**, please first [create an issue](../../issues/new) for discussion.
31 |
32 | The steps to submit a PR are:
33 |
34 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device.
35 |
36 | 2. Install all dependencies and dev dependencies by `npm install`.
37 |
38 | 3. Make changes and commit (following [commit message styleguides](#commit-message)).
39 |
40 | 4. Make sure your code is linted by running `npm run lint`.
41 |
42 | 5. [Create a pull request](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork)
43 |
44 | ## Styleguides
45 |
46 | ### Javascript style
47 |
48 | `nextjs-mongodb-app` follows [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript). Please run `npm run lint` and fix any linting warnings.
49 |
50 | ### Commit message
51 |
52 | - Use the present tense and imperative mood ("Add feature" instead of "Adds feature" or "Added feature")
53 | - Consider starting the commit message with an applicable emoji (ex. [gitmoji](https://gitmoji.carloscuesta.me)) for a more beautiful world :rainbow:.
54 |
55 | :heart: Thank you,
56 | Hoang Vo
57 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Hoang Vo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Next.js + MongoDB + Basic Crud Operation
2 |
3 | A full-fledged app made with Next.JS and MongoDB.
4 |
5 | ## About this project
6 |
7 | `nextjs-mongo-crud` is a continously developed app built with Next.JS and MongoDB. Most tutorials on the Internet are either _half-baked_ or _not production-ready_. This project aims to fix that.
8 |
9 | This project goes even further and attempts to integrate top features as seen in real-life apps.
10 |
11 | Give this project a big ol' 🌟 star motivates me to work on new features.
12 |
13 | Check out my profile (https://tejasrana.com/).
14 |
15 | ## Using this project
16 |
17 | The goal is not to use this project as it, but to implement your own version.
18 |
19 | ### Requirement
20 |
21 | This project relies on the following components. Some of them are **optional** and some may be replaced by others with similar functionalities.
22 |
23 | #### Dependencies
24 |
25 | This project uses the following dependencies:
26 |
27 | - `next.js` - v9 or above required for **API Routes**.
28 | - `react` - v16.8 or above required for **react hooks**.
29 | - `react-dom` - v16.8 or above.
30 | - `mongodb` - may be replaced by `mongoose`.
31 | - `next-connect` - recommended if you want to use Express/Connect middleware.
32 | - `axios`, `axioswal` - optional, may be replaced with any request library.
33 | - `next-session`, `connect-mongo` - may be replaced with any session management solution.
34 | - `bcryptjs` - optional, may be replaced with any password-hashing library. `argon2` recommended.
35 | - `validator` - optional but recommended.
36 | - `formidable` - may be replaced by other file parser.
37 | - `cloudinary` - optional, only if you are using [Cloudinary](https://cloudinary.com) for image upload.
38 |
39 | #### Environmental variables
40 |
41 | The environment variables [will be inlined during build time](https://nextjs.org/docs#build-time-configuration) and thus should not be used in front-end codebase.
42 |
43 | Required environmental variables in this project include:
44 |
45 | - `process.env.MONGODB_URI` The MongoDB Connection String (with credentials)
46 | - `process.env.CLOUDINARY_URL` Cloudinary environment variable for configuration. See [this](https://cloudinary.com/documentation/node_integration#configuration "Cloudinary Configuration").
47 | - `process.env.DB_NAME` The name of the MongoDB database to be used.
48 |
49 | I include my own MongoDB and Cloudinary environment variables in [.env.example](.env.example) for experimentation purposes. Please replace them with your owns and refrain from sabotaging them. You can use them in development by renaming it into `.env`.
50 |
51 | In production, it is recommended to set the environment variables using the options provided by your cloud/hosting providers.
52 |
53 | ## Development
54 |
55 | `nextjs-mongo-crud` is a long-term developing project. There is no constraint on numbers of features. I continuously accepts feature proposals and am actively developing and expanding functionalities.
56 |
57 | Start the development server by running `yarn dev` or `npm run dev`.
58 |
59 | ### Features
60 |
61 | There are three states in feature development:
62 |
63 | - `developed`: The feature has been fully developed and is functional.
64 | - `developing`: The feature is being developed or being improved.
65 | - `proposed`: The feature is proposed and may or may not be developed in the future.
66 |
67 | #### Authentication
68 |
69 | - Session management
70 | - Allow users to sign up and log in/log out.
71 |
72 | #### User profile
73 |
74 | - Avatar, name, email, location, etc.
75 | - User profile page
76 | - Edit user profile
77 |
78 | #### Social `delayed`
79 |
80 | - Find other users with search functionality
81 | - View other users' profile page
82 | - Add/Remove friends
83 |
84 | #### Account management `developing`
85 |
86 | - Email verification
87 | - Password change
88 | - Password reset
89 |
90 | Have any features in mind, [make an issue](https://github.com/tejasrana95/nextjs-mongo-crud/issues). Would like to work on a feature, [make a PR](https://github.com/tejasrana95/nextjs-mongo-crud/pulls).
91 |
92 | ### Styles
93 |
94 | Despite the look, this project does not contain any stylesheets, and no component has classes. To remove the style, simply remove all `
63 |
106 |
107 |
40 | To start using this starter kit, please uncomment every commented line in _app.jsx and index.jsx.
41 |
42 | Then the screen show you an error code: 500 in /api/session.
43 |
44 | Don't panic, please just configure the connection with your database in .env file and you can connect with your choice of database.
45 |