Improve self host support (#28)
* Add docker setup for self hosting * Add ses settings tables
This commit is contained in:
37
apps/web/src/server/api/routers/admin.ts
Normal file
37
apps/web/src/server/api/routers/admin.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { z } from "zod";
|
||||
import { env } from "~/env";
|
||||
|
||||
import { createTRPCRouter, adminProcedure } from "~/server/api/trpc";
|
||||
import { SesSettingsService } from "~/server/service/ses-settings-service";
|
||||
|
||||
export const adminRouter = createTRPCRouter({
|
||||
getSesSettings: adminProcedure.query(async () => {
|
||||
return SesSettingsService.getAllSettings();
|
||||
}),
|
||||
|
||||
addSesSettings: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
region: z.string(),
|
||||
unsendUrl: z.string().url(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
return SesSettingsService.createSesSetting({
|
||||
region: input.region,
|
||||
unsendUrl: input.unsendUrl,
|
||||
});
|
||||
}),
|
||||
|
||||
getSetting: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
region: z.string().optional().nullable(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
return SesSettingsService.getSetting(
|
||||
input.region ?? env.AWS_DEFAULT_REGION
|
||||
);
|
||||
}),
|
||||
});
|
@@ -10,6 +10,7 @@
|
||||
import { initTRPC, TRPCError } from "@trpc/server";
|
||||
import superjson from "superjson";
|
||||
import { ZodError } from "zod";
|
||||
import { env } from "~/env";
|
||||
|
||||
import { getServerAuthSession } from "~/server/auth";
|
||||
import { db } from "~/server/db";
|
||||
@@ -123,3 +124,13 @@ export const teamProcedure = protectedProcedure.use(async ({ ctx, next }) => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* To manage application settings, for hosted version, authenticated users will be considered as admin
|
||||
*/
|
||||
export const adminProcedure = protectedProcedure.use(async ({ ctx, next }) => {
|
||||
if (env.NEXT_PUBLIC_IS_CLOUD && ctx.session.user.email !== env.ADMIN_EMAIL) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
}
|
||||
return next();
|
||||
});
|
||||
|
Reference in New Issue
Block a user