Skip to content

Commit

Permalink
fix: format
Browse files Browse the repository at this point in the history
  • Loading branch information
vinicius-sacramento committed Sep 17, 2024
1 parent 28ab07d commit 2e56404
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
18 changes: 13 additions & 5 deletions packages/api/src/jwt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const createSessionToken = async (signedSessionData: SignedPayload) => {
};

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const token = jwt.sign(tokenData, "95614424651656c92f70fcc90980fbf25607a87e9fa487d913f455cc740cbd79", jwtOptions());
const token = jwt.sign(
tokenData,
"95614424651656c92f70fcc90980fbf25607a87e9fa487d913f455cc740cbd79",
jwtOptions(),
);

return token;
};
Expand All @@ -68,10 +72,14 @@ export const decodeJwtSessionToken = (token: string): { userKey: string } => {
export function isJwtTokenValid(token: string) {
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const decodedToken = jwt.verify(token, "95614424651656c92f70fcc90980fbf25607a87e9fa487d913f455cc740cbd79", {
algorithms: ["HS256"],
issuer: "commune-ts",
}) as jwt.JwtPayload;
const decodedToken = jwt.verify(
token,
"95614424651656c92f70fcc90980fbf25607a87e9fa487d913f455cc740cbd79",
{
algorithms: ["HS256"],
issuer: "commune-ts",
},
) as jwt.JwtPayload;

// Check if the token has expired
const currentTimestamp = Math.floor(Date.now() / 1000);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { publicProcedure } from "../trpc";
export const authRouter = {
startSession: publicProcedure
.input(SignedPayloadSchema)
.mutation( async ({ input }) => {
.mutation(async ({ input }) => {
const token = await createSessionToken(input);
// TODO: somehow check that the userKey is an valid commune/substrate address

Expand Down
23 changes: 16 additions & 7 deletions packages/api/src/router/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const daoRouter = {
.input(DAO_VOTE_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.user!.userKey
const userKey = ctx.user!.userKey;
await ctx.db
.update(daoVoteSchema)
.set({
Expand All @@ -56,13 +56,16 @@ export const daoRouter = {
)
.execute();

await ctx.db.insert(daoVoteSchema).values({...input, userKey: userKey}).execute();
await ctx.db
.insert(daoVoteSchema)
.values({ ...input, userKey: userKey })
.execute();
}),
deleteVote: authenticatedProcedure
.input(z.object({ daoId: z.number() }))
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.user!.userKey
const userKey = ctx.user!.userKey;
await ctx.db
.update(daoVoteSchema)
.set({
Expand All @@ -79,14 +82,20 @@ export const daoRouter = {
.input(CADRE_CANDIDATES_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.user!.userKey
await ctx.db.insert(cadreCandidatesSchema).values({...input, userKey: userKey }).execute();
const userKey = ctx.user!.userKey;
await ctx.db
.insert(cadreCandidatesSchema)
.values({ ...input, userKey: userKey })
.execute();
}),
createCadreVote: authenticatedProcedure
.input(CADRE_VOTE_INSERT_SCHEMA)
.mutation(async ({ ctx, input }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userKey = ctx.user!.userKey
await ctx.db.insert(cadreVoteSchema).values({...input, userKey: userKey }).execute();
const userKey = ctx.user!.userKey;
await ctx.db
.insert(cadreVoteSchema)
.values({ ...input, userKey: userKey })
.execute();
}),
} satisfies TRPCRouterRecord;
2 changes: 1 addition & 1 deletion packages/db/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const USER_MODULE_DATA_INSERT_SCHEMA = createInsertSchema(
},
).omit({
id: true,
userKey: true
userKey: true,
});

export const DAO_VOTE_INSERT_SCHEMA = createInsertSchema(daoVoteSchema).omit({
Expand Down

0 comments on commit 2e56404

Please sign in to comment.