All Projects โ†’ alexcambose โ†’ JWT-user-auth-API-bolilerplate

alexcambose / JWT-user-auth-API-bolilerplate

Licence: other
Boilerplate for backend API user authentication with JWT

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to JWT-user-auth-API-bolilerplate

Appy Backend
A user system to bootstrap your app.
Stars: โœญ 96 (+638.46%)
Mutual labels:  login, users
vue-koa2-login
๐Ÿฅ Vue + Koa2 ๅฎž็Žฐๅ‰ๅŽ็ซฏๆณจๅ†Œ็™ปๅฝ•ๆต็จ‹
Stars: โœญ 23 (+76.92%)
Mutual labels:  login, jsonwebtoken
Userfrosting
๐Ÿฉ Modern PHP user login and management framework++.
Stars: โœญ 1,547 (+11800%)
Mutual labels:  login, users
Kratos
Next-gen identity server (think Auth0, Okta, Firebase) with Ory-hardened authentication, MFA, FIDO2, profile management, identity schemas, social sign in, registration, account recovery, and IoT auth. Golang, headless, API-only - without templating or theming headaches.
Stars: โœญ 4,684 (+35930.77%)
Mutual labels:  login, users
hapi-doorkeeper
User authentication for web servers
Stars: โœญ 14 (+7.69%)
Mutual labels:  login, auth0
Cloudfront Auth
An AWS CloudFront [emailย protected] function to authenticate requests using Google Apps, Microsoft, Auth0, OKTA, and GitHub login
Stars: โœญ 471 (+3523.08%)
Mutual labels:  login, auth0
Authing
๐Ÿ”ฅAuthing - IDaaS/IAM solution that can Auth to web and mobile applications.
Stars: โœญ 247 (+1800%)
Mutual labels:  login, auth0
Fake Api Jwt Json Server
A Fake API with JWT Authentication using json-server and jsonwebtoken
Stars: โœญ 151 (+1061.54%)
Mutual labels:  jsonwebtoken, jwt-authentication
spring-boot-login-example
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example
Stars: โœญ 50 (+284.62%)
Mutual labels:  login, jwt-authentication
electron-auth0-login
Helper widget for Auth0 authentication in Electron desktop apps
Stars: โœญ 23 (+76.92%)
Mutual labels:  login, auth0
reactjs-login-register-crud
ReactJS CRUD Application, ReactJS FileUpload, ReactJS Sample application, ReactJS Boilerplate, ReactJS Login, ReactJS FileUpload, ReactJS Register
Stars: โœญ 47 (+261.54%)
Mutual labels:  login, jwt-authentication
drf-angular-docker-tutorial
Dockerized Django Back-end API using DRF with Angular Front-end Tutorial
Stars: โœญ 53 (+307.69%)
Mutual labels:  auth0, jwt-authentication
user login and register
user login and register system in django
Stars: โœญ 43 (+230.77%)
Mutual labels:  login, users
Auth0.js
Auth0 headless browser sdk
Stars: โœญ 755 (+5707.69%)
Mutual labels:  login, auth0
authentication
A framework agnostic authentication library based on PSR standards
Stars: โœญ 19 (+46.15%)
Mutual labels:  login, jwt-authentication
Supertokens Core
Open source alternative to Auth0 / Firebase Auth / AWS Cognito
Stars: โœญ 2,907 (+22261.54%)
Mutual labels:  login, auth0
task-manager
Task Manager App
Stars: โœญ 19 (+46.15%)
Mutual labels:  jsonwebtoken, jwt-authentication
Delphimvcframework
DMVCFramework (for short) is a popular and powerful framework for web solution in Delphi. Supports RESTful and JSON-RPC APIs development.
Stars: โœญ 761 (+5753.85%)
Mutual labels:  jsonwebtoken, jwt-authentication
rocket auth
An implementation for an authentication API for Rocket applications.
Stars: โœญ 65 (+400%)
Mutual labels:  login, users
springboot-graphql-sqqr-jwt-demo
GraphQL java backend representing the right way to authenticate/authorize using Spring boot, graphql-spqr & jsonwebtoken
Stars: โœญ 28 (+115.38%)
Mutual labels:  jsonwebtoken, jwt-authentication

JWT-user-authentication-API-bolilerplate

Build Status

Express JSON API with JWT user authentication.

Installation

npm install

Usage

npm run dev will start a development server with nodemon

npm run prod will start NODE_ENV=production production server

File structure

โ”œโ”€โ”€ app
โ”‚   โ”œโ”€โ”€ controllers
โ”‚   โ”‚   โ””โ”€โ”€ user.js         # Exports functions to use in routers
โ”‚   โ”œโ”€โ”€ logs                # Contains all the logs
โ”‚   โ”œโ”€โ”€ models              # Contains all models
โ”‚   โ”‚   โ””โ”€โ”€ User.js         # User model
โ”‚   โ”œโ”€โ”€ routes              # contains all routes
โ”‚   โ”‚   โ”œโ”€โ”€ api             # where /api/ routes are stored
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ index.js    # separates public from private routes with a middleware
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ private.js  # contains all private routes
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ public.js   # contains all public routes
โ”‚   โ”‚   โ””โ”€โ”€ index.js        # where / routes are stored
โ”‚   โ”œโ”€โ”€ translations        # message translations
โ”‚   โ”œโ”€โ”€ server.js           # where the server starts and routes for the root path
โ”‚   โ””โ”€โ”€ utils.js            # useful functions used in the entire application
โ”œโ”€โ”€ config.js               # where all JWT, Winston, Mongoose,... config goes
โ”œโ”€โ”€ index.js                # entry point, where mongoose connects to mongodb
โ”œโ”€โ”€ public                  # public directory, should be used for serving static assets
โ”‚   โ””โ”€โ”€ index.html

Static routes

/ will serve files from /public

Public Routes

POST /api/user/register

Parameters:

  1. email unique
  2. first_name
  3. last_name
  4. password

POST /api/user/login

Parameters:

  1. email
  2. password

Returns:

  • user user object
  • token jwt token

Private Routes

In order to access private routes you MUST pass the token parameter that is given when logging in.

GET /api/user - Returns the user from the database, useful for refreshing user data.

POST /api/user - Updates user data

Parameters:

Any user field that you want to update, _id, meta and __v will be ignored.

POST /api/user/checkpassword - Returns true if the provided password is the same as the user's one

Parameters: password Current user password that you want to check.

DELETE /api/user - Deletes the user

Examples

Login example

fetch('http://localhost:3000/api/user/login', {
        method: 'POST',
        body: JSON.stringify({
            email: '[email protected]',
            password: 'thepassword'
        }),
        headers: {
            'Content-Type': 'application/json'
        },
    })
    .then(res => res.json())
    .then(res => {
        if(res.success){ // {success: true, user: {...}, token: "..."}
            localStorage.setItem('token', res.token);
            localStorage.setItem('user', JSON.stringify(res.user)); // *optional*
        }else{ // {success: false, message: "..."}
            console.log(res.message);
        }
    })
    .catch(error => {
        // some server error
        console.log("Error connecting to server: " + error);
    });

Update user

 fetch('http://localhost:3000/api/user', {
        method: 'POST',
        body: JSON.stringify({
            token: localStorage.getItem('token'),
            first_name: 'Jomajino'
        }),
        headers: {
            'Content-Type': 'application/json',
        }
    })
    .then(res => res.json())
    .then(res => {
        if(res.success){ // {success: true}
            //update the user in local storage
            let user = JSON.parse(localStorage.getItem('user'));
            user.first_name = 'Jomajino';
            localStorage.setItem('user', JSON.stringify(user));
        }else{ // {success: false, message: "..."}
            console.log(res.message);
        }
    })
    .catch(error => {
        // some server error
        console.log("Error connecting to server: " + error);
    });

Traslations helper library: Polylang


License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].