1.0.10 • Published 2 years ago

repl-auth v1.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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 coding398 - Cool tester + has great ideas + bug fixer

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.10

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago