@tripsi-app/logto-server-auth
v1.0.1
Published
Logto JWT verification and feature-flag-path RBAC for Express
Downloads
249
Maintainers
Readme
@tripsi-app/logto-server-auth
Logto JWT verification and feature-flag-path RBAC for Express.
Install
npm install @tripsi-app/logto-server-auth expressThis package declares express as a peer dependency. TypeScript projects using Express 4 should also install @types/express.
npm install -D @types/expressUsage
import express from 'express';
import { createLogtoAuth } from '@tripsi-app/logto-server-auth';
const app = express();
const auth = createLogtoAuth({
logto: {
LOGTO_ENDPOINT: process.env.LOGTO_ENDPOINT!,
LOGTO_RESOURCE: process.env.LOGTO_RESOURCE,
},
allFeatureFlagPaths: ['/feature/a', '/feature/b'],
roles: ['admin', 'user'],
roleFeaturePaths: {
admin: ['/feature/a', '/feature/b'],
user: ['/feature/a'],
},
});
app.use(auth.requireLogtoAuth());
app.get('/api/hello', (req, res) => {
const user = req.logtoUser;
res.json({ sub: user?.id });
});
app.listen(3000);See exported types and createLogtoAuth in the package for full options (e.g. requireFeaturePathForRoute, authenticateRequest).
License
ISC
