This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/packages/dashboard/pages/api/hello.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-02-03 14:06:44 +00:00
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2021-02-04 13:31:26 +00:00
import jwt from "express-jwt";
import jwks from "jwks-rsa";
import config from "../../src/config";
// This middleware assumes that the app is secured using ORY Oathkeeper, in which case we
// verify the JSON Web Token issued by ORY Oathkeeper using the jwt-express middleware.
const middleware = jwt({
// Dynamically provide a signing key based on the kid in the header and the signing keys provided by the JWKS endpoint.
secret: jwks.expressJwtSecret({
cache: true,
jwksRequestsPerMinute: 5,
jwksUri: config.jwksUrl,
}),
algorithms: ["RS256"],
});
2021-02-05 10:54:05 +00:00
// Helper method to wait for a middleware to execute before continuing
// And to throw an error when an error happens in a middleware
function runMiddleware(req, res, fn) {
return new Promise((resolve, reject) => {
fn(req, res, (result) => {
if (result instanceof Error) {
return reject(result);
}
return resolve(result);
});
});
}
2021-02-05 10:55:10 +00:00
export default async (req, res) => {
await runMiddleware(req, res, middleware);
2021-02-05 10:54:05 +00:00
2021-02-04 13:31:26 +00:00
console.log(Object.keys(req));
2021-02-05 10:58:20 +00:00
console.log(req.user);
2021-02-03 14:06:44 +00:00
res.statusCode = 200;
res.json({ name: "John Doe" });
2021-02-05 10:54:05 +00:00
};