Skip to content

Commit 0943a17

Browse files
committed
feat: Auth and User Endpoints exposed for basic operations
1 parent 26faa5b commit 0943a17

23 files changed

+10588
-1
lines changed

.gitignore

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
# VsCode directory
107+
.vscode/
108+
109+
# Public directory
110+
public/
111+
112+
# SQLite and Storage
113+
storage/
114+
database/SQLite/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Dibesh Raj Subedi
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.

README.md

Lines changed: 199 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,200 @@
11
# AuthJs
2-
A simple authentication project for beginners to start frontend integration
2+
3+
!["JS"](https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black) !["Express"](https://img.shields.io/badge/Express.js-000000?style=for-the-badge&logo=express&logoColor=white) !["Node"](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white) !["yarn"](https://img.shields.io/badge/yarn-CB3837?style=for-the-badge&logo=yarn&logoColor=white) !["SQLITE"](https://img.shields.io/badge/SQLite-07405E?style=for-the-badge&logo=sqlite&logoColor=white) !["Markdown"](https://img.shields.io/badge/Markdown-000000?style=for-the-badge&logo=markdown&logoColor=white) !["VSCode"](https://img.shields.io/badge/VSCode-0078D4?style=for-the-badge&logo=visual%20studio%20code&logoColor=white) !["JSON"](https://img.shields.io/badge/json-5E5C5C?style=for-the-badge&logo=json&logoColor=white)
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+
![Folder Structure](./docs/Folder_Structure.png)
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+
![Swagger Implementation](./docs/Swagger_Implementation.png)
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

Comments
 (0)