Giter VIP home page Giter VIP logo

jwt-login's Introduction

jwt-login

a training vessel with Sails

This is an example of a simple device-agnostic backend that implements login, signup, and logout using JSON Web Tokens. It is based on the basic-login example, modified to use JWT instead of server-side sessions.

This is a simple Single-Page App (SPA) that loads a single view (view/main.ejs) to start, then loads content by making AJAX requests with jQuery (using an Authorization header with the JWT token if it has one) and replacing the contents of the #content div. This is not intended as a tutorial on building SPAs, which would normally use a framework like Angular or React. Note also that the JWT is not persisted in the front end (it's just saved in memory), so that refreshing the page will log the user out. See this page for a discussion on options for storing your web tokens to persist logins between page loads.

Relevant bits

  • views/main.ejs contains the main HTML wrapper and all of the front-end Javascript.
  • api/controllers/UserController.js contains the back-end code for signing up and logging in users, including creating new JWTs.
  • api/policies/isAuthenticated.js contains the code for authenticating a user via JWT, and redirecting unauthorized users to the login page
  • api/policies/checkForUser.js is similar to isAuthenticated.js, but allows logged-out users to continue. This is useful for things like the home page, which can display a customized welcome message to logged-in users but should be available to everyone.

jwt-login's People

Contributors

sgress454 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.