Files
freeCodeCamp/api/middleware/index.ts
Mrugesh Mohapatra 7199f033fb feat(next-api): basic authentication setup (#49378)
* feat(next-api): add fastify-auth0-verify plugin

* feat(next-api): add fastify-jwt-authz plugin

* feat(next-api): accept privacy endpoint with scopes support

* fix(next-api): ignore eslint and ts errors

They will be fixed in a future PR when the package with errors has been updated

Co-authored-by: Niraj Nandish <nirajnandish@icloud.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2023-02-24 17:26:40 +05:30

26 lines
672 B
TypeScript

import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import type { NextFunction, NextHandleFunction } from '@fastify/middie';
export async function auth0Verify(
this: FastifyInstance,
request: FastifyRequest,
reply: FastifyReply
) {
await this.authenticate(request, reply);
}
type MiddieRequest = Parameters<NextHandleFunction>[0];
type MiddieResponse = Parameters<NextHandleFunction>[1];
export function testMiddleware(
req: MiddieRequest,
res: MiddieResponse,
next: NextFunction
) {
console.log('Test middleware running');
console.log(req.headers);
console.log(req.query);
res.setHeader('X-Test-Header', 'test');
next();
}