Giter Site home page Giter Site logo

work-hours-backend's Introduction

Express Typescript app starter template with passport.js authentication

Use this starter template for your express project that needs passport.js jwt authentication strategy and Typescript.

Forked from: https://github.com/zachgoll/express-jwt-authentication-starter

How to use this Repo

You can use this repo as a starter template for an Express app that needs passport.js jwt authentication and Typescript. This starter is especially suitable for Express.js backend that is connected to SPA frontend (React, Angular or similar). More information about the usage of passport.js can be found from the original repository.

You will need to start the Mongo DB database using the mongod process. You can run this process persistently in the background, but you could also just type mongod in your terminal.

Next, you will need to generate a public/private keypair. The .gitignore automatically ignores the private key. To generate the keypair run

npm run generateKeypair

Quickstart

Start the Express server in dev mode (http://localhost:3000)

npm run dev

Build the project for production use

npm run build

Run the production build (after building the project first)

npm start

Authentication flow

You can test the authentication with HTTP client of your preference, I use Postman. The app currently has three routes: /users/register, /users/login, /users/protected. You should be able to perform the following authentication flow:

  1. POST /users/register with object
{
    "username": "your-username", 
    "password": "your-password" 
}

as the request body.

  1. POST /users/login with the same object in the body as in the registration. You should get a response that contains field "token". Copy the token string starting with "Bearer..". Copy the token without the quotation marks.

  2. GET /users/protected with your token attached to the Authorization header. You should get a response message "You are succesfully authenticated for this route!"

If you got successfully to phase 3, the app starter is working correctly and you can start building your app!

work-hours-backend's People

Contributors

tterimaa avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.