GithubHelp home page GithubHelp logo

codingmaster398 / replauth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dainfloop/replace-replit

0.0 0.0 0.0 132 KB

Home Page: replit.com/@haroon/replauth

License: MIT License

JavaScript 36.23% TypeScript 61.47% Nix 2.30%

replauth's Introduction

repl-auth

Use Replit's Repl Auth in your project without hosting on Replit.

Usage

Replit

Use this exactly how you'd use @replit/repl-auth:

import { getUserInfo } from "repl-auth";
import express from "express";

const app = express();

app.get('/', (req, res) => {
  const user = getUserInfo(req);

  if (user)
    res.send(`Hello, ${user.name}!`);
  else
    res.send(`Hello, World!`);
});

app.listen(8000, () => {
  console.log("App is running on port 8000");
});

Anywhere else

The module only supports express currently.

import { express as replAuth } from "repl-auth";
import express from "express";

const app = express();
app.use(replAuth());

app.get('/', (req, res) => {
  const username = req.get("X-Replit-User-Name");

  if (username)
    res.send(`Hello, ${username}!`);
  else
    res.send(`Hello, World!`);
});

app.listen(8000, () => {
  console.log("App is running on port 8000");
});

Options

Currently there is only one option passable to the replAuth middleware:

exposeAs will allow you to control what an object containing the user data will be set to:

app.use(replAuth({ exposeAs: "user" }))

// In a route handler...
req.user.name // contains the user's username

Acknowledgements

PotentialStyx - Helped me with verifying the JWT
PikachuB2005 - Donated the package name to me

replauth's People

Contributors

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