|
1 | 1 | # AuthJs
|
2 |
| -A simple authentication project for beginners to start frontend integration |
| 2 | + |
| 3 | +         |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [AuthJs](#authjs) |
| 8 | + - [Table of Contents](#table-of-contents) |
| 9 | + - [Introduction](#introduction) |
| 10 | + - [Requirements](#requirements) |
| 11 | + - [Setup](#setup) |
| 12 | + - [Pre-Requisites](#pre-requisites) |
| 13 | + - [Assumptions](#assumptions) |
| 14 | + - [Suggestions](#suggestions) |
| 15 | + - [Instructions](#instructions) |
| 16 | + - [Directory Structure](#directory-structure) |
| 17 | + - [What is exposed](#what-is-exposed) |
| 18 | + - [Resolve PORT Conflict](#resolve-port-conflict) |
| 19 | + - [Ubuntu](#ubuntu) |
| 20 | + - [Windows](#windows) |
| 21 | + - [Support](#support) |
| 22 | + - [Issues](#issues) |
| 23 | + |
| 24 | +## Introduction |
| 25 | + |
| 26 | +This is a dummy project that helps you to start your frontend project and setup a basic authentication flow. |
| 27 | + |
| 28 | +## Requirements |
| 29 | + |
| 30 | +- [NodeJs](https://nodejs.org/en/) installed `v12.x.x` or higher. |
| 31 | +- [Yarn](https://classic.yarnpkg.com/lang/en/docs/install) installed -> use `yarn install --global yarn` if you want to setup yarn |
| 32 | + |
| 33 | +Thats it for the requirements. |
| 34 | + |
| 35 | +## Setup |
| 36 | + |
| 37 | +Setting up project is relatively easy if you have `Node.js` installed in your pc. |
| 38 | + |
| 39 | +1. Clone the repo or download the repo from [https://github.com/itSubeDibesh/ImageServer](https://github.com/itSubeDibesh/ImageServer) |
| 40 | +2. Open terminal pointing to cloned directory and follow the [Instructions](#instructions) section. |
| 41 | + |
| 42 | +### Pre-Requisites |
| 43 | + |
| 44 | +1. Internet connection to download required packages. |
| 45 | +1. [**Node.js version 12.x.x or higher. (v14+ recommended)**](https://nodejs.org/) |
| 46 | +1. [**VisualStudio Code (VsCode) latest version.**](https://code.visualstudio.com/) |
| 47 | + |
| 48 | +### Assumptions |
| 49 | + |
| 50 | +I assume that the user has installed Node.js version 12.x.x or higher. (v14+ recommended) and the user has internet connection to download required packages. The user knows how to install **Node.js** version 12.x.x or higher if not installed. The user also have basic knowledge of how to use **command line** and **VsCode**. |
| 51 | + |
| 52 | +### Suggestions |
| 53 | + |
| 54 | +Please use VisualStudio Code(VsCode) to have a better experience exploring files and all the documents of the project. Open the "Readme.md" file in VsCode and use "ctrl+shift+v" command to have a better experience. |
| 55 | + |
| 56 | +### Instructions |
| 57 | + |
| 58 | + To run the project open your command line interface (CLI) and navigate to the current directory and observe whether the `node_modules` folder is created. If not then run the following command: |
| 59 | + |
| 60 | +```bash |
| 61 | + yarn setup |
| 62 | +``` |
| 63 | + |
| 64 | + This will install all the required _packages_. Now simply run another command to start the project: |
| 65 | + |
| 66 | +``` bash |
| 67 | + yarn dev |
| 68 | +``` |
| 69 | + |
| 70 | +You would see your browser opening URL `http://localhost:8080/docs`. If it does not check the terminal [CLI] which would show logs as shown in below. |
| 71 | + |
| 72 | +```bash |
| 73 | +Index: Working on Development Mode. |
| 74 | +📡 Server is running in Development mode |
| 75 | +🌎 Setting up HTTP Server |
| 76 | +📚 Swagger Documentation is available at http://localhost:8080/docs/ |
| 77 | +📚 Swagger Documentation is available at http://localhost:8080/docs/ |
| 78 | +🛠 Configuring HTTP Routes |
| 79 | +🔗 Establishing API Controller [Auth] at [/api/auth/] with E:/Practice/authJs/backend/controllers/api/Auth.js |
| 80 | +Index: Working on Development Mode. |
| 81 | +📡 Server is running in Development mode |
| 82 | +Index: Working on Development Mode. |
| 83 | +📡 Server is running in Development mode |
| 84 | +🌎 Setting up HTTP Server |
| 85 | +📚 Swagger Documentation is available at http://localhost:8080/docs/ |
| 86 | +📚 Swagger Documentation is available at http://localhost:8080/docs/ |
| 87 | +🛠 Configuring HTTP Routes |
| 88 | +🔗 Establishing API Controller [Auth] at [/api/auth/] with E:/Practice/authJs/backend/controllers/api/Auth.js |
| 89 | +🔗 Establishing API Controller [User] at [/api/user/] with E:/Practice/authJs/backend/controllers/api/User.js |
| 90 | +👂 Connection Established, Serving HTTP with URL [http://localhost:8080] |
| 91 | +``` |
| 92 | + |
| 93 | +Open your browser navigate to `http://localhost:8080/docs` URl and you are good to go. |
| 94 | + |
| 95 | +### Directory Structure |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +1. [backend](./backend/) directory -> All the web/api controllers. |
| 100 | +1. [configuration](./configuration/) directory -> All the Configurations. |
| 101 | +1. [database](./database/) directory -> All the Scripts and Database files. |
| 102 | +1. [documents](./documents/) directory -> All necessary images and documents. |
| 103 | +1. [library](./library/) directory -> All custom written Codes |
| 104 | +1. [node_modules](./node_modules/) -> All the packages and dependencies. |
| 105 | + |
| 106 | +`index.js` file is the initial file that server requires whereas `cleanup.js` file is used to remove create a fresh setup of project wiping all information in database as well as images stored in `storage` directory. |
| 107 | + |
| 108 | +⚠️ Warning : Don't Run `yarn clean` or `yarn setup` unless you want a fresh setup. |
| 109 | + |
| 110 | +## What is exposed |
| 111 | + |
| 112 | +When you navigate to browser and open `http://localhost:8080/docs` you will see. |
| 113 | + |
| 114 | + |
| 115 | +Every endpoints requires a csrf token which can be obtained from `http://localhost:8080/api/auth/csrf` and every user routs along with `login_check` routes requires **Authorization** header which can be achieved once you hit `http://localhost:8080/api/auth/login` route. |
| 116 | + |
| 117 | +## Resolve PORT Conflict |
| 118 | + |
| 119 | +When you see following message in console it means a PORT conflict has arise. |
| 120 | + |
| 121 | +```bash |
| 122 | +node:events:371 |
| 123 | + throw er; // Unhandled 'error' event |
| 124 | + ^ |
| 125 | + |
| 126 | +Error: listen EADDRINUSE: address already in use :::8080 |
| 127 | + at Server.setupListenHandle [as _listen2] (node:net:1319:16) |
| 128 | + at listenInCluster (node:net:1367:12) |
| 129 | + at Server.listen (node:net:1454:7) |
| 130 | + at Function.listen (E:\College\Advanced Cyber Security\ImageServer\node_modules\express\lib\application.js:635:24) |
| 131 | + at Server.#listenHttp (E:\College\Advanced Cyber Security\ImageServer\library\server\lib.server.express.js:418:14) |
| 132 | + at Server.setupHTTP (E:\College\Advanced Cyber Security\ImageServer\library\server\lib.server.express.js:521:25) |
| 133 | + at Server.setUpServer (E:\College\Advanced Cyber Security\ImageServer\library\server\lib.server.express.js:535:31) |
| 134 | + at Object.<anonymous> (E:\College\Advanced Cyber Security\ImageServer\index.js:85:6) |
| 135 | + at Module._compile (node:internal/modules/cjs/loader:1101:14) |
| 136 | + at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) |
| 137 | +Emitted 'error' event on Server instance at: |
| 138 | + at emitErrorNT (node:net:1346:8) |
| 139 | + at processTicksAndRejections (node:internal/process/task_queues:83:21) { |
| 140 | + code: 'EADDRINUSE', |
| 141 | + errno: -4091, |
| 142 | + syscall: 'listen', |
| 143 | + address: '::', |
| 144 | + port: 8080 |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +To Fix this issue we have different solution as per the operating system. |
| 149 | + |
| 150 | +### Ubuntu |
| 151 | + |
| 152 | +Find PID using following command |
| 153 | + |
| 154 | +```bash |
| 155 | +lsof -i TCP:8080 | grep LISTEN |
| 156 | +``` |
| 157 | + |
| 158 | +It would result in something like |
| 159 | + |
| 160 | +```bash |
| 161 | +node 2464 user 21u IPv6 4392639 0t0 TCP *:http-alt |
| 162 | +``` |
| 163 | + |
| 164 | +The Second colum after node is PID, kill the PID using following command |
| 165 | + |
| 166 | +```bash |
| 167 | +kill -9 2464 |
| 168 | +``` |
| 169 | + |
| 170 | +### Windows |
| 171 | + |
| 172 | +Find the PID using following command |
| 173 | + |
| 174 | +```bash |
| 175 | +netstat -ano | findstr :8080 |
| 176 | +``` |
| 177 | + |
| 178 | +WHich would return something like |
| 179 | + |
| 180 | +```bash |
| 181 | + TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 24552 |
| 182 | + TCP [::]:8080 [::]:0 LISTENING 24552 |
| 183 | +``` |
| 184 | + |
| 185 | +Kill the PID at last after LISTENING using following command |
| 186 | + |
| 187 | +```bash |
| 188 | +taskkill /PID 24552 /F |
| 189 | +``` |
| 190 | + |
| 191 | +## Support |
| 192 | + |
| 193 | +If you have any issues please contact me at: |
| 194 | + |
| 195 | + |
| 196 | +LinkedIn : [https://www.linkedin.com/in/itsubedibesh](https://www.linkedin.com/in/itsubedibesh) |
| 197 | + |
| 198 | +## Issues |
| 199 | + |
| 200 | +Checkout [https://github.com/Sniper-Code/AuthJs/issues](https://github.com/Sniper-Code/AuthJs/issues) for any issues or to fill an issue. |
0 commit comments