Skip to content

Commit

Permalink
lint + format
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguyinabeanie committed Nov 8, 2024
1 parent b630ef6 commit 80e3ac5
Show file tree
Hide file tree
Showing 28 changed files with 1,302 additions and 1,092 deletions.
2 changes: 0 additions & 2 deletions packages/api/src/root.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { authRouter } from "./router/auth";
import { postRouter } from "./router/post";
import { createTRPCRouter } from "./trpc";

export const appRouter = createTRPCRouter({
auth: authRouter,
post: postRouter,
});

// export type definition of API
Expand Down
40 changes: 0 additions & 40 deletions packages/api/src/router/post.ts

This file was deleted.

13 changes: 8 additions & 5 deletions packages/api/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* tl;dr - this is where all the tRPC server stuff is created and plugged in.
* The pieces you will need to use are documented accordingly near the end
*/
import type { Session } from "@clerk/nextjs/server";
import type { AuthObject } from "@clerk/backend";
import { auth } from "@clerk/nextjs/server";
import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
Expand All @@ -27,7 +27,7 @@ const isomorphicGetSession = async (headers: Headers) => {
// return validateToken(authToken);
}
// return auth();
return auth();
return await auth();
};

/**
Expand All @@ -44,8 +44,11 @@ const isomorphicGetSession = async (headers: Headers) => {
*/
export const createTRPCContext = async (opts: {
headers: Headers;
session: Session | null;
}) => {
}): Promise<{
session: AuthObject | null;
db: typeof db;
token: string | null;
}> => {
const authToken = opts.headers.get("Authorization") ?? null;
const session = await isomorphicGetSession(opts.headers);

Expand Down Expand Up @@ -138,7 +141,7 @@ export const publicProcedure = t.procedure.use(timingMiddleware);
export const protectedProcedure = t.procedure
.use(timingMiddleware)
.use(({ ctx, next }) => {
if (!ctx.session.userId) {
if (!ctx.session?.userId) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
return next({
Expand Down
Loading

0 comments on commit 80e3ac5

Please sign in to comment.