mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
tRPC Authorization 미들웨어 구현
This commit is contained in:
@@ -1,9 +1,25 @@
|
||||
import type { RequestEvent } from "@sveltejs/kit";
|
||||
import { initTRPC } from "@trpc/server";
|
||||
import { initTRPC, TRPCError } from "@trpc/server";
|
||||
import { authorizeMiddleware, authorizeClientMiddleware } from "./middlewares/authorize";
|
||||
|
||||
export const createContext = (event: RequestEvent) => event;
|
||||
|
||||
const t = initTRPC.context<Awaited<ReturnType<typeof createContext>>>().create();
|
||||
export const t = initTRPC.context<Awaited<ReturnType<typeof createContext>>>().create();
|
||||
|
||||
export const router = t.router;
|
||||
export const publicProcedure = t.procedure;
|
||||
|
||||
const authedProcedure = publicProcedure.use(async ({ ctx, next }) => {
|
||||
if (!ctx.locals.session) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
}
|
||||
return next();
|
||||
});
|
||||
|
||||
export const roleProcedure = {
|
||||
any: authedProcedure.use(authorizeMiddleware("any")),
|
||||
notClient: authedProcedure.use(authorizeMiddleware("notClient")),
|
||||
anyClient: authedProcedure.use(authorizeClientMiddleware("anyClient")),
|
||||
pendingClient: authedProcedure.use(authorizeClientMiddleware("pendingClient")),
|
||||
activeClient: authedProcedure.use(authorizeClientMiddleware("activeClient")),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user