initial commit

This commit is contained in:
Syahdan 2026-04-29 17:01:16 +07:00
commit 33e75c056f
77 changed files with 4329 additions and 0 deletions

View file

@ -0,0 +1,18 @@
import { auth } from "@minmon/auth";
import type { Context as ElysiaContext } from "elysia";
export type CreateContextOptions = {
context: ElysiaContext;
};
export async function createContext({ context }: CreateContextOptions) {
const session = await auth.api.getSession({
headers: context.request.headers,
});
return {
auth: null,
session,
};
}
export type Context = Awaited<ReturnType<typeof createContext>>;

25
packages/api/src/index.ts Normal file
View file

@ -0,0 +1,25 @@
import { initTRPC, TRPCError } from "@trpc/server";
import type { Context } from "./context";
export const t = initTRPC.context<Context>().create();
export const router = t.router;
export const publicProcedure = t.procedure;
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Authentication required",
cause: "No session",
});
}
return next({
ctx: {
...ctx,
session: ctx.session,
},
});
});

View file

@ -0,0 +1,14 @@
import { protectedProcedure, publicProcedure, router } from "../index";
export const appRouter = router({
healthCheck: publicProcedure.query(() => {
return "OK";
}),
privateData: protectedProcedure.query(({ ctx }) => {
return {
message: "This is private",
user: ctx.session.user,
};
}),
});
export type AppRouter = typeof appRouter;