Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat: add configuration endpoint and integrate config handling in sign-up flow

Andrej Acevski700266d237c5
diff --git a/apps/api/src/config/index.ts b/apps/api/src/config/index.ts
new file mode 100644
index 000000000..09e6d4b82
--- /dev/null
+++ b/apps/api/src/config/index.ts
@@ -0,0 +1,10 @@
+import { Hono } from "hono";
+import getSettings from "../utils/get-settings";
+
+const config = new Hono().get("/", async (c) => {
+ const settings = getSettings();
+
+ return c.json(settings);
+});
+
+export default config;
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index c72103386..2a88636b3 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -4,6 +4,7 @@ import { Hono } from "hono";
import { getCookie } from "hono/cookie";
import { cors } from "hono/cors";
import activity from "./activity";
+import config from "./config";
import db from "./database";
import githubIntegration from "./github-integration";
import label from "./label";
@@ -31,6 +32,8 @@ app.use(
}),
);
+const configRoute = app.route("/config", config);
+
const githubIntegrationRoute = app.route(
"/github-integration",
githubIntegration,
@@ -127,4 +130,5 @@ export type AppType =
| typeof labelRoute
| typeof notificationRoute
| typeof publicProjectRoute
- | typeof githubIntegrationRoute;
+ | typeof githubIntegrationRoute
+ | typeof configRoute;
diff --git a/apps/web/src/components/auth/toggle.tsx b/apps/web/src/components/auth/toggle.tsx
index 4206baa5e..67be2a8b2 100644
--- a/apps/web/src/components/auth/toggle.tsx
+++ b/apps/web/src/components/auth/toggle.tsx
@@ -1,3 +1,4 @@
+import useGetConfig from "@/hooks/queries/config/use-get-config";
import { Link } from "@tanstack/react-router";
interface AuthToggleProps {
@@ -7,6 +8,12 @@ interface AuthToggleProps {
}
export function AuthToggle({ message, linkText, linkTo }: AuthToggleProps) {
+ const { data: config } = useGetConfig();
+
+ if (config?.disableRegistration) {
+ return null;
+ }
+
return (
<div className="mt-6 text-center">
<p className="text-sm text-zinc-600 dark:text-zinc-400">
diff --git a/apps/web/src/fetchers/config/get-config.ts b/apps/web/src/fetchers/config/get-config.ts
new file mode 100644
index 000000000..c7c906172
--- /dev/null
+++ b/apps/web/src/fetchers/config/get-config.ts
@@ -0,0 +1,18 @@
+import { client } from "@kaneo/libs";
+import type { InferResponseType } from "hono/client";
+
+export type GetConfigResponse = InferResponseType<
+ (typeof client)["config"]["$get"]
+>;
+
+export async function getConfig() {
+ const response = await client.config.$get();
+
+ if (!response.ok) {
+ const error = await response.text();
+ throw new Error(error);
+ }
+
+ const data = await response.json();
+ return data;
+}
diff --git a/apps/web/src/hooks/queries/config/use-get-config.ts b/apps/web/src/hooks/queries/config/use-get-config.ts
new file mode 100644
index 000000000..0eb0e3c97
--- /dev/null
+++ b/apps/web/src/hooks/queries/config/use-get-config.ts
@@ -0,0 +1,11 @@
+import { getConfig } from "@/fetchers/config/get-config";
+import { useQuery } from "@tanstack/react-query";
+
+function useGetConfig() {
+ return useQuery({
+ queryKey: ["config"],
+ queryFn: getConfig,
+ });
+}
+
+export default useGetConfig;
diff --git a/apps/web/src/routes/auth/sign-up.tsx b/apps/web/src/routes/auth/sign-up.tsx
index b96a054ab..d649e0ad1 100644
--- a/apps/web/src/routes/auth/sign-up.tsx
+++ b/apps/web/src/routes/auth/sign-up.tsx
@@ -2,10 +2,18 @@ import { AuthLayout } from "@/components/auth/layout";
import { SignUpForm } from "@/components/auth/sign-up-form";
import { AuthToggle } from "@/components/auth/toggle";
import PageTitle from "@/components/page-title";
-import { createFileRoute } from "@tanstack/react-router";
+import { getConfig } from "@/fetchers/config/get-config";
+import { createFileRoute, redirect } from "@tanstack/react-router";
export const Route = createFileRoute("/auth/sign-up")({
component: SignUp,
+ beforeLoad: async () => {
+ const config = await getConfig();
+
+ if (config.disableRegistration) {
+ redirect({ to: "/auth/sign-in", replace: true });
+ }
+ },
});
function SignUp() {