Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
steinerkelvin committed Oct 7, 2024
1 parent 7107c3a commit 42da7b2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const JWT_OPTIONS: jwt.SignOptions = {
// issuer: "commune-ts",
};

export const createSessionToken = async (
export const createSessionToken = (
tokenData: SessionData,
jwtSecret: string,
) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/auth/sign.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use server";

import { hexToString, stringToHex } from "@polkadot/util";
import { signatureVerify, cryptoWaitReady } from "@polkadot/util-crypto";
import { cryptoWaitReady, signatureVerify } from "@polkadot/util-crypto";

import type { SignedPayload } from "@commune-ts/types";
import { checkSS58, AUTH_REQ_SCHEMA } from "@commune-ts/types";
import { AUTH_REQ_SCHEMA, checkSS58 } from "@commune-ts/types";

export const signData = async <T>(
signer: (
Expand Down Expand Up @@ -33,7 +33,7 @@ export const verifySignedData = async (signedInput: SignedPayload) => {
throw new Error("Invalid signature");
}

const unmarshed = JSON.parse(hexToString(payload));
const unmarshed = JSON.parse(hexToString(payload)) as unknown;
const validated = AUTH_REQ_SCHEMA.safeParse(unmarshed);
if (!validated.success) {
throw new Error(`Invalid payload: ${validated.error.message}`);
Expand Down
8 changes: 6 additions & 2 deletions packages/api/src/router/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { TRPCRouterRecord } from "@trpc/server";
import { TRPCError } from "@trpc/server";

import { AuthReq, SIGNED_PAYLOAD_SCHEMA } from "@commune-ts/types";
import type { AuthReq } from "@commune-ts/types";
import { SIGNED_PAYLOAD_SCHEMA } from "@commune-ts/types";

import { createSessionToken } from "../auth";
import { verifySignedData } from "../auth/sign";
Expand All @@ -16,10 +17,12 @@ export const authRouter = {
.input(SIGNED_PAYLOAD_SCHEMA)
.mutation(async ({ ctx, input }) => {
try {
// eslint-disable-next-line no-var
var { address, payload } = await verifySignedData(input);
} catch (err) {
throw new TRPCError({
code: "BAD_REQUEST",
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
message: `Invalid signed payload: ${err}`,
cause: err,
});
Expand All @@ -30,12 +33,13 @@ export const authRouter = {
} catch (err) {
throw new TRPCError({
code: "BAD_REQUEST",
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
message: `Invalid authentication request: ${err}`,
cause: err,
});
}

const token = await createSessionToken(
const token = createSessionToken(
{
userKey: address,
uri: payload.uri,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const createTRPCContext = (opts: {
assert(sessionData.uri === opts.authOrigin);
// TODO: verify JWT
} catch (err) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.error(`Failed to validate JWT: ${err}`);
}
}
Expand Down

0 comments on commit 42da7b2

Please sign in to comment.