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 DISABLE_GUEST_ACCESS environment variable

Andrej Acevski9641324edd11
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index e40efd14c..f0b7c29d5 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -95,12 +95,20 @@ export const auth = betterAuth({
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
},
+ discord: {
+ clientId: process.env.DISCORD_CLIENT_ID || "",
+ clientSecret: process.env.DISCORD_CLIENT_SECRET || "",
+ },
},
plugins: [
- anonymous({
- generateName: async () => generateDemoName(),
- emailDomainName: "kaneo.com",
- }),
+ ...(process.env.DISABLE_GUEST_ACCESS !== "true"
+ ? [
+ anonymous({
+ generateName: async () => generateDemoName(),
+ emailDomainName: "kaneo.com",
+ }),
+ ]
+ : []),
lastLoginMethod(),
magicLink({
sendMagicLink: async ({ email, url }) => {
diff --git a/apps/api/src/utils/get-settings.ts b/apps/api/src/utils/get-settings.ts
index 8c02cee63..8e3105320 100644
--- a/apps/api/src/utils/get-settings.ts
+++ b/apps/api/src/utils/get-settings.ts
@@ -18,9 +18,13 @@ function getSettings() {
hasGoogleSignIn:
Boolean(process.env.GOOGLE_CLIENT_ID) &&
Boolean(process.env.GOOGLE_CLIENT_SECRET),
+ hasDiscordSignIn:
+ Boolean(process.env.DISCORD_CLIENT_ID) &&
+ Boolean(process.env.DISCORD_CLIENT_SECRET),
hasCustomOAuth:
Boolean(process.env.CUSTOM_OAUTH_CLIENT_ID) &&
Boolean(process.env.CUSTOM_OAUTH_CLIENT_SECRET),
+ hasGuestAccess: process.env.DISABLE_GUEST_ACCESS !== "true",
};
}
diff --git a/apps/web/src/routes/auth/sign-in.tsx b/apps/web/src/routes/auth/sign-in.tsx
index ccfbb8a63..4e9b2c69f 100644
--- a/apps/web/src/routes/auth/sign-in.tsx
+++ b/apps/web/src/routes/auth/sign-in.tsx
@@ -22,6 +22,7 @@ function SignIn() {
const [isCustomOAuthLoading, setIsCustomOAuthLoading] = useState(false);
const [isGithubLoading, setIsGithubLoading] = useState(false);
const [isGoogleLoading, setIsGoogleLoading] = useState(false);
+ const [isDiscordLoading, setIsDiscordLoading] = useState(false);
const [isGuestLoading, setIsGuestLoading] = useState(false);
const lastLoginMethod = authClient.getLastUsedLoginMethod();
const { data: config, isLoading: isConfigLoading } = useGetConfig();
@@ -115,6 +116,30 @@ function SignIn() {
}
};
+ const handleSignInDiscord = async () => {
+ setIsDiscordLoading(true);
+ try {
+ const result = await authClient.signIn.social({
+ provider: "discord",
+ callbackURL: `${import.meta.env.VITE_CLIENT_URL}/dashboard`,
+ errorCallbackURL: `${import.meta.env.VITE_CLIENT_URL}/auth/sign-in`,
+ });
+ if (result.error) {
+ throw new Error(result.error.message);
+ }
+ toast.success("Signed in with Discord");
+ navigate({ to: "/dashboard" });
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to sign in with Discord",
+ );
+ } finally {
+ setIsDiscordLoading(false);
+ }
+ };
+
if (isConfigLoading) {
return (
<>
@@ -139,6 +164,7 @@ function SignIn() {
<div className="mt-6">
{(config?.hasGoogleSignIn ||
config?.hasGithubSignIn ||
+ config?.hasDiscordSignIn ||
config?.hasCustomOAuth) && (
<>
<div className="space-y-3">
@@ -201,6 +227,39 @@ function SignIn() {
</div>
)}
+ {config?.hasDiscordSignIn && (
+ <div className="relative">
+ <Button
+ variant="outline"
+ onClick={handleSignInDiscord}
+ disabled={isDiscordLoading}
+ className={cn(
+ "w-full",
+ lastLoginMethod === "discord" && "border-primary/50!",
+ )}
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ className="w-5 h-5 mr-2"
+ fill="currentColor"
+ aria-label="Discord"
+ >
+ <title>Discord</title>
+ <path d="M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515a.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0a12.64 12.64 0 0 0-.617-1.25a.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 0 0 .031.057a19.9 19.9 0 0 0 5.993 3.03a.078.078 0 0 0 .084-.028a14.09 14.09 0 0 0 1.226-1.994a.076.076 0 0 0-.041-.106a13.107 13.107 0 0 1-1.872-.892a.077.077 0 0 1-.008-.128a10.2 10.2 0 0 0 .372-.292a.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127a12.299 12.299 0 0 1-1.873.892a.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028a19.839 19.839 0 0 0 6.002-3.03a.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419c0-1.333.956-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419c0-1.333.955-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.946 2.418-2.157 2.418z" />
+ </svg>
+ {isDiscordLoading
+ ? "Signing in..."
+ : "Continue with Discord"}
+ </Button>
+ {lastLoginMethod === "discord" && (
+ <span className="absolute rounded-md -top-3 right-1 px-1.5 text-xs text-primary font-medium bg-sidebar border border-primary/50">
+ Last used
+ </span>
+ )}
+ </div>
+ )}
+
{config?.hasCustomOAuth && (
<div className="relative">
<Button
@@ -225,15 +284,17 @@ function SignIn() {
</div>
)}
- <Button
- variant="outline"
- onClick={handleGuestAccess}
- disabled={isGuestLoading}
- className="w-full"
- >
- <UserCheck className="w-4 h-4 mr-2" />
- {isGuestLoading ? "Signing in..." : "Continue as guest"}
- </Button>
+ {config?.hasGuestAccess && (
+ <Button
+ variant="outline"
+ onClick={handleGuestAccess}
+ disabled={isGuestLoading}
+ className="w-full"
+ >
+ <UserCheck className="w-4 h-4 mr-2" />
+ {isGuestLoading ? "Signing in..." : "Continue as guest"}
+ </Button>
+ )}
</div>
<div className="relative my-6">
diff --git a/apps/web/src/routes/auth/sign-up.tsx b/apps/web/src/routes/auth/sign-up.tsx
index 2d5f4e08b..2b7619189 100644
--- a/apps/web/src/routes/auth/sign-up.tsx
+++ b/apps/web/src/routes/auth/sign-up.tsx
@@ -8,6 +8,7 @@ import { AuthToggle } from "@/components/auth/toggle";
import PageTitle from "@/components/page-title";
import { Button } from "@/components/ui/button";
import { getConfig } from "@/fetchers/config/get-config";
+import useGetConfig from "@/hooks/queries/config/use-get-config";
import { authClient } from "@/lib/auth-client";
export const Route = createFileRoute("/auth/sign-up")({
@@ -24,6 +25,7 @@ export const Route = createFileRoute("/auth/sign-up")({
function SignUp() {
const navigate = useNavigate();
const [isGuestLoading, setIsGuestLoading] = useState(false);
+ const { data: config } = useGetConfig();
const handleGuestAccess = async () => {
setIsGuestLoading(true);
@@ -51,21 +53,25 @@ function SignUp() {
subtitle="Get started with your workspace"
>
<div className="space-y-4 mt-6">
- <Button
- variant="outline"
- onClick={handleGuestAccess}
- disabled={isGuestLoading}
- className="w-full mb-0"
- size="sm"
- >
- <UserCheck className="w-4 h-4 mr-2" />
- {isGuestLoading ? "Signing in..." : "Continue as guest"}
- </Button>
- <div className="flex items-center gap-4 my-4">
- <div className="flex-1 h-px bg-zinc-200 dark:bg-zinc-800" />
- <span className="text-sm text-zinc-500 dark:text-zinc-400">or</span>
- <div className="flex-1 h-px bg-zinc-200 dark:bg-zinc-800" />
- </div>
+ {config?.hasGuestAccess && (
+ <Button
+ variant="outline"
+ onClick={handleGuestAccess}
+ disabled={isGuestLoading}
+ className="w-full mb-0"
+ size="sm"
+ >
+ <UserCheck className="w-4 h-4 mr-2" />
+ {isGuestLoading ? "Signing in..." : "Continue as guest"}
+ </Button>
+ )}
+ {config?.hasGuestAccess && (
+ <div className="flex items-center gap-4 my-4">
+ <div className="flex-1 h-px bg-zinc-200 dark:bg-zinc-800" />
+ <span className="text-sm text-zinc-500 dark:text-zinc-400">or</span>
+ <div className="flex-1 h-px bg-zinc-200 dark:bg-zinc-800" />
+ </div>
+ )}
<SignUpForm />
<AuthToggle
message="Already have an account?"