Giter VIP home page Giter VIP logo

lit-locked-react-app-minimal-example's Introduction

Intro

This example code shows how to lock an entire react app behind a Lit JWT.

The react app lives in the client/ folder.

This can be deployed to Heroku and it should work out of the box.

Note that you'll need to modify the access control conditions and resource id in server.js for your own application.

How it works

Inside server.js, we selectively serve the react app if the user presents a valid JWT created via the Lit Protocol in a query param. We save that JWT in a session cookie so that it's sent with every request, and check it on every request.

You should be able to drop any react app into the "client" folder to protect it with a Lit JWT

Example code

This app expects a Lit JWT in the query param "jwt". To test generating this JWT, you can use example.html.

Steps:

  1. cd client and then yarn build to build your React app. During development, you can use yarn start to start the server on port 3000 instead of using yarn build. Note, however, that when running in dev mode via yarn start, the content isn't protected by server.js and any token gating or access control condition gating will not be applied.
  2. When you're ready to test the protection in server.js, and you've already build the app in the client directory with yarn build, then you can run yarn start to start the server in the root of the repository.
  3. You can then visit http://localhost:5000/example.html in your browser to see the example app. The example app will mint an NFT (step 1), provision access to this server to only permit users who hold that NFT (step 2), request a jwt to use to send to the server (step 3), and finally redirect you to the server with the JWT as a url parameter (step 4).

Note that minting the nft (step 1) is entirely optional, and in your own code, you may choose to use an already existing NFT instead of minting a new one. You should choose your own accessControlConditions and resourceId and set those in example.html (if you wish to use it for testing), and in server.js.

lit-locked-react-app-minimal-example's People

Contributors

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