This repository focuses on providing an example of jwt authentication, user roles management and internationalization.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Ensure you have Node.js on your local machine.
-
Clone the repo 📦
$ git clone 'https://github.com/MilfuegosDEV/JWT-AUTH.git' $ cd JWT-AUTH
-
Setup .env file 🔒
PORT=4000 MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database CLIENT_NAME=<CLIENT_NAME> CLIENT_LASTNAME=<CLIENT_LASTNAME> CLIENT_EMAIL=<CLIENT_EMAIL> CLIENT_SECRET=<CLIENT_PASSWORD> JWT_SECRET=<YOUR_KEY>
-
Install dependencies 💣
$ yarn install
-
Start the app 😀
$ npm run dev
-
PORT=4000
:- Specifies the port on which your server will run. In this case, the server will listen on port 4000.
-
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database
:- Sets the MongoDB connection URI. Replace
username
,password
, andcluster.mongodb.net
with your actual MongoDB credentials and cluster information.database
should be the name of the MongoDB database.
- Sets the MongoDB connection URI. Replace
-
CLIENT_NAME=<CLIENT_NAME>
:- This appears to be a placeholder for the client's name. You would replace
<CLIENT_NAME>
with the actual name of the client.
- This appears to be a placeholder for the client's name. You would replace
-
CLIENT_LASTNAME=<CLIENT_LASTNAME>
:- Similar to
CLIENT_NAME
, this is a placeholder for the client's last name. Replace<CLIENT_LASTNAME>
with the actual last name of the client.
- Similar to
-
CLIENT_EMAIL=<CLIENT_EMAIL>
:- Placeholder for the client's email address. Replace
<CLIENT_EMAIL>
with the actual email address of the client.
- Placeholder for the client's email address. Replace
-
CLIENT_SECRET=<CLIENT_PASSWORD>
:- Placeholder for the client's password or secret. Replace
<CLIENT_PASSWORD>
with the actual password or secret for the client. Note that storing secrets directly in environment variables might not be the most secure practice. Consider more secure methods if this is for production.
- Placeholder for the client's password or secret. Replace
-
JWT_SECRET=<YOUR_KEY>
:- Sets the secret key used for signing JSON Web Tokens (JWT). Replace
<YOUR_KEY>
with a secure secret key. This key is crucial for the security of your authentication system, so make sure it's a strong and secret value.
- Sets the secret key used for signing JSON Web Tokens (JWT). Replace
Each configuration option in the .env
file serves a specific purpose in configuring and customizing your application. It's important to keep sensitive information, such as database credentials and secret keys, secure and not expose them publicly.
- build: Compiles the source code.
- dev: Starts the app in development mode.
- start: Starts the compiled app.
JWT-AUTH
├───build // compiled src
|
├───src
| │ index.js
│ │
│ ├───app
│ │ ├───config // Configuration files.
│ │ ├───controllers // Controllers for handling business logic
│ │ ├───libs // Libraries or utility functions that are used across the application.
│ │ ├───middlewares // functions that can be applied to specific routes or globally.
│ │ ├───models // Moongose models representing MongoDB collections
│ │ ├───routes // Route definitions for different parts of this api.
│ │ └───services // Bussiness logic services.
│ │
│ └───resources // Resources used in this project.
│ └───locales // Languages files for translations.
│
├───.env
├───.gitignore
├───README.md
└───yarn.lock
Feel free to contribute! Follow these steps to get started.
- Fork repo.
- Create your feature branch.
- Commit your changes.
- Push to the branch.
- Open a pull request.
This project is under the MIT License. See the LICENSE file for more details. Feel free to modify and customize the template based on your project's specifics and requirements.