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.

fix(auth): restore guest sign-in access (#1391)

Tin Severd7281e1a20be
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index 2a5140305..40e52c46d 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -485,6 +485,16 @@ export const auth = betterAuth({
user: {
create: {
before: async (user, ctx) => {
+ // The anonymous() plugin creates ephemeral users for guest
+ // access; registration limits don't apply to them (guest
+ // availability is governed by DISABLE_GUEST_ACCESS instead).
+ // `isAnonymous` is `input: false` in the plugin schema, so a
+ // regular signup request cannot spoof it.
+ const userWithAnonymous = user as Partial<UserWithAnonymous>;
+ if (userWithAnonymous.isAnonymous) {
+ return;
+ }
+
// Allow the very first signup through even when registration
// is disabled — that's the instance-admin bootstrap flow.
// Otherwise a fresh instance with DISABLE_REGISTRATION=true
diff --git a/apps/web/src/routes/auth/sign-in.tsx b/apps/web/src/routes/auth/sign-in.tsx
index e9784f13d..894bad2ac 100644
--- a/apps/web/src/routes/auth/sign-in.tsx
+++ b/apps/web/src/routes/auth/sign-in.tsx
@@ -3,7 +3,7 @@ import {
useNavigate,
useSearch,
} from "@tanstack/react-router";
-import { Github, KeyRound } from "lucide-react";
+import { Github, KeyRound, UserCheck } from "lucide-react";
import { useCallback, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { z } from "zod/v4";
@@ -20,6 +20,11 @@ import { OtpSignInForm } from "../../components/auth/otp-sign-in-form";
import { SignInForm } from "../../components/auth/sign-in-form";
import { SignInFormSkeleton } from "../../components/auth/sign-in-form-skeleton";
import { AuthToggle } from "../../components/auth/toggle";
+import { Turnstile } from "../../components/auth/turnstile";
+
+const TURNSTILE_SITE_KEY = import.meta.env.VITE_TURNSTILE_SITE_KEY as
+ | string
+ | undefined;
const signInSearchSchema = z.object({
invitationId: z.string().optional(),
@@ -41,6 +46,8 @@ function SignIn() {
const [isGithubLoading, setIsGithubLoading] = useState(false);
const [isGoogleLoading, setIsGoogleLoading] = useState(false);
const [isDiscordLoading, setIsDiscordLoading] = useState(false);
+ const [isGuestLoading, setIsGuestLoading] = useState(false);
+ const [turnstileToken, setTurnstileToken] = useState<string | null>(null);
const [autoLoginFailed, setAutoLoginFailed] = useState(false);
const lastLoginMethod = authClient.getLastUsedLoginMethod();
const { data: config, isLoading: isConfigLoading } = useGetConfig();
@@ -73,6 +80,15 @@ function SignIn() {
const invitationId = search.invitationId;
const defaultEmail = search.email;
+ const captchaConfigured = Boolean(TURNSTILE_SITE_KEY);
+ const captchaPending = captchaConfigured && !turnstileToken;
+
+ const handleTurnstileVerify = useCallback((token: string) => {
+ setTurnstileToken(token);
+ }, []);
+ const handleTurnstileExpire = useCallback(() => {
+ setTurnstileToken(null);
+ }, []);
const getSafeRedirectPath = useCallback(() => {
const redirectPath = search.redirect;
@@ -186,6 +202,25 @@ function SignIn() {
}
};
+ const handleGuestAccess = async () => {
+ if (captchaPending) return;
+ setIsGuestLoading(true);
+ try {
+ const result = await authClient.signIn.anonymous();
+ if (result.error) {
+ throw new Error(result.error.message);
+ }
+ toast.success(t("auth:signIn.guestSuccess"));
+ handleSignInSuccess();
+ } catch (error) {
+ toast.error(
+ error instanceof Error ? error.message : t("auth:signIn.guestError"),
+ );
+ } finally {
+ setIsGuestLoading(false);
+ }
+ };
+
useEffect(() => {
if (search.error) {
setAutoLoginFailed(true);
@@ -264,7 +299,8 @@ function SignIn() {
{(config?.hasGoogleSignIn ||
config?.hasGithubSignIn ||
config?.hasDiscordSignIn ||
- config?.hasCustomOAuth) && (
+ config?.hasCustomOAuth ||
+ (config?.hasGuestAccess && !invitationId)) && (
<>
<div className="space-y-3">
{config?.hasGoogleSignIn && (
@@ -382,6 +418,30 @@ function SignIn() {
)}
</div>
)}
+
+ {config?.hasGuestAccess && !invitationId && (
+ <>
+ <Button
+ variant="outline"
+ onClick={handleGuestAccess}
+ disabled={isGuestLoading || captchaPending}
+ className="w-full"
+ >
+ <UserCheck className="w-5 h-5 mr-2" />
+ {isGuestLoading
+ ? t("auth:signIn.signingIn")
+ : t("auth:signUp.continueAsGuest")}
+ </Button>
+ {captchaConfigured && TURNSTILE_SITE_KEY && (
+ <Turnstile
+ siteKey={TURNSTILE_SITE_KEY}
+ onVerify={handleTurnstileVerify}
+ onExpire={handleTurnstileExpire}
+ onError={handleTurnstileExpire}
+ />
+ )}
+ </>
+ )}
</div>
{!config?.disableLoginForm && (