Skip to content

Commit

Permalink
Optimize Verify Code
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed May 30, 2022
1 parent 4aad982 commit 3109f3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/routes/api/domains/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { generateSunflake } from 'sunflake';

import { DB } from '../../../database';
import { useAuth } from '../../../util/http/useAuth';
import { log } from '../../../util/logging';
import { Poof } from '../../../util/sentry/sentryHandle';

export const generateSnowflake = generateSunflake();
Expand All @@ -18,7 +19,11 @@ export const DomainLsRoute: FastifyPluginAsync = async (router, options) => {
const authData = (await useAuth(_request, reply)) as Poof | string;

if (determineIfAuth(authData)) {
return reply.status(authData.status).send();
reply.status(authData.status || 500);
reply.send();
log.ok(...authData.logMessages);

return;
}

reply.send(
Expand Down
9 changes: 8 additions & 1 deletion src/util/http/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const useAuth: (
auth = auth.slice('Bearer '.length);
}

console.log(auth);

const decoded = decode(auth) as { address: string; user_id: string };

if (!decoded)
Expand All @@ -43,11 +45,16 @@ export const useAuth: (
logMessages: ['Key "user_id" was missing from payload'],
};

if (verify(auth, process.env.SIGNAL_MASTER))
console.log(process.env.SIGNAL_MASTER);

try {
verify(auth, process.env.SIGNAL_MASTER);
} catch {
return {
status: 403,
logMessages: ['Invalid signature on payload'],
};
}

const owner = await DB.selectOneFrom('owners', ['user_id'], {
address: decoded.address,
Expand Down

0 comments on commit 3109f3e

Please sign in to comment.