Redact URLs before logging

This commit is contained in:
Stan Wohlwend 2024-03-02 15:56:53 +01:00
parent e334df1a88
commit d0b2c8fd1c
2 changed files with 9 additions and 4 deletions

View File

@ -63,11 +63,16 @@ export async function parseRequest<T>(req: NextRequest, schema: yup.Schema<T>):
export function smartRouteHandler(handler: (req: NextRequest, options: any) => Promise<Response>): (req: NextRequest, options: any) => Promise<Response> {
return async (req: NextRequest, options: any) => {
try {
console.log(`[API REQ] ${req.method} ${req.url}`);
const censoredUrl = new URL(req.url);
for (const key of censoredUrl.searchParams.keys()) {
censoredUrl.searchParams.set(key, "--REDACTED--");
}
console.log(`[API REQ] ${req.method} ${censoredUrl}`);
const timeStart = performance.now();
const res = await handler(req, options);
const time = (performance.now() - timeStart);
console.log(`[ RES] ${req.method} ${req.url} (in ${time.toFixed(0)}ms)`);
console.log(`[ RES] ${req.method} ${censoredUrl} (in ${time.toFixed(0)}ms)`);
return res;
} catch (e) {
// catch some Next.js non-errors and rethrow them

View File

@ -14,8 +14,8 @@ export default function OauthCallback () {
if (called.current) return;
called.current = true;
await app.callOauthCallback();
await router.push(app.urls.userHome);
router.push(app.urls.userHome);
}), []);
return <MessageCard title='Redirecting...' fullPage />;
}
}