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): let invited users without an account register

boredinnyc1e55596677ce
diff --git a/apps/web/src/routes/auth/verify-otp.test.tsx b/apps/web/src/routes/auth/verify-otp.test.tsx
new file mode 100644
index 000000000..992bf5820
--- /dev/null
+++ b/apps/web/src/routes/auth/verify-otp.test.tsx
@@ -0,0 +1,100 @@
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@testing-library/react";
+import type { ComponentType, ReactNode } from "react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { Route } from "./verify-otp";
+
+// The OTP input measures itself on mount, which jsdom cannot do.
+vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+);
+
+const emailOtp = vi.fn();
+const push = vi.fn();
+
+let search: {
+ email: string;
+ invitationId?: string;
+ redirect?: string;
+} = { email: "[email protected]" };
+
+vi.mock("@tanstack/react-router", () => ({
+ createFileRoute: () => (options: unknown) => options,
+ Link: ({ children }: { children: ReactNode }) => <a href="/">{children}</a>,
+ useRouter: () => ({ history: { push } }),
+ useSearch: () => search,
+}));
+
+vi.mock("@/lib/auth-client", () => ({
+ authClient: {
+ signIn: {
+ emailOtp: (
+ body: { email: string; otp: string },
+ fetchOptions?: { headers: Record<string, string> },
+ ) => emailOtp(body, fetchOptions),
+ },
+ emailOtp: { sendVerificationOtp: vi.fn() },
+ },
+}));
+
+vi.mock("@/lib/toast", () => ({
+ toast: { error: vi.fn(), success: vi.fn() },
+}));
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+const VerifyOtp = (Route as unknown as { component: ComponentType }).component;
+
+function submitCode() {
+ render(<VerifyOtp />);
+ fireEvent.change(screen.getByRole("textbox"), {
+ target: { value: "123456" },
+ });
+}
+
+beforeEach(() => {
+ emailOtp.mockResolvedValue({ data: {}, error: null });
+});
+
+afterEach(() => {
+ cleanup();
+ emailOtp.mockReset();
+ push.mockReset();
+ search = { email: "[email protected]" };
+});
+
+describe("VerifyOtp", () => {
+ it("forwards the invitation so a first OTP sign-in can create the account", async () => {
+ search = { email: "[email protected]", invitationId: "invitation-1" };
+
+ submitCode();
+
+ await waitFor(() => expect(emailOtp).toHaveBeenCalledTimes(1));
+ expect(emailOtp).toHaveBeenCalledWith(
+ { email: "[email protected]", otp: "123456" },
+ { headers: { "x-invitation-id": "invitation-1" } },
+ );
+ });
+
+ it("sends no invitation header when the visitor arrived without one", async () => {
+ submitCode();
+
+ await waitFor(() => expect(emailOtp).toHaveBeenCalledTimes(1));
+ expect(emailOtp).toHaveBeenCalledWith(
+ { email: "[email protected]", otp: "123456" },
+ undefined,
+ );
+ });
+});
diff --git a/apps/web/src/routes/auth/verify-otp.tsx b/apps/web/src/routes/auth/verify-otp.tsx
index e3d9e5e56..3a354467b 100644
--- a/apps/web/src/routes/auth/verify-otp.tsx
+++ b/apps/web/src/routes/auth/verify-otp.tsx
@@ -77,10 +77,18 @@ function VerifyOtp() {
async (data: VerifyOtpFormValues) => {
setIsPending(true);
try {
- const result = await authClient.signIn.emailOtp({
- email,
- otp: data.otp,
- });
+ // A first-time OTP sign-in creates the account, so instances with
+ // DISABLE_REGISTRATION=true reject it unless the request carries the
+ // invitation the visitor arrived with.
+ const result = await authClient.signIn.emailOtp(
+ {
+ email,
+ otp: data.otp,
+ },
+ invitationId
+ ? { headers: { "x-invitation-id": invitationId } }
+ : undefined,
+ );
if (result.error) {
toast.error(
diff --git a/apps/web/src/routes/invitation/accept.$inviteId.test.tsx b/apps/web/src/routes/invitation/accept.$inviteId.test.tsx
new file mode 100644
index 000000000..499c05315
--- /dev/null
+++ b/apps/web/src/routes/invitation/accept.$inviteId.test.tsx
@@ -0,0 +1,93 @@
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import type { ComponentType, ReactNode } from "react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { Route } from "./accept.$inviteId";
+
+const navigate = vi.fn();
+const useSession = vi.fn();
+const useGetInvitationDetails = vi.fn();
+
+vi.mock("@tanstack/react-router", () => ({
+ createFileRoute: () => (options: unknown) => options,
+ Link: ({ children }: { children: ReactNode }) => <a href="/">{children}</a>,
+ useNavigate: () => navigate,
+ useParams: () => ({ inviteId: "invitation-1" }),
+}));
+
+vi.mock("@/hooks/queries/invitation/use-get-invitation-details", () => ({
+ useGetInvitationDetails: (invitationId: string) =>
+ useGetInvitationDetails(invitationId),
+}));
+
+vi.mock("@/lib/auth-client", () => ({
+ authClient: {
+ useSession: () => useSession(),
+ },
+}));
+
+vi.mock("@/lib/toast", () => ({
+ toast: { error: vi.fn(), success: vi.fn() },
+}));
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+ Trans: ({ i18nKey }: { i18nKey: string }) => <span>{i18nKey}</span>,
+}));
+
+const AcceptInvitation = (Route as unknown as { component: ComponentType })
+ .component;
+
+function renderSignedOutInvitation() {
+ useSession.mockReturnValue({ data: null, isPending: false });
+ useGetInvitationDetails.mockReturnValue({
+ data: {
+ valid: true,
+ invitation: {
+ id: "invitation-1",
+ email: "[email protected]",
+ workspaceName: "Kaneo",
+ inviterName: "Ada",
+ expiresAt: "2999-01-01T00:00:00.000Z",
+ status: "pending",
+ expired: false,
+ },
+ },
+ isLoading: false,
+ error: null,
+ });
+
+ render(<AcceptInvitation />);
+}
+
+afterEach(() => {
+ cleanup();
+ navigate.mockReset();
+});
+
+describe("AcceptInvitation", () => {
+ it("sends an invitee without an account to sign-up with the invitation", () => {
+ renderSignedOutInvitation();
+
+ fireEvent.click(
+ screen.getByRole("button", { name: "auth:invitation.createAccount" }),
+ );
+
+ expect(navigate).toHaveBeenCalledWith({
+ to: "/auth/sign-up",
+ search: { invitationId: "invitation-1", email: "[email protected]" },
+ });
+ });
+
+ it("keeps the sign-in route for invitees who already have an account", () => {
+ renderSignedOutInvitation();
+
+ fireEvent.click(
+ screen.getByRole("button", { name: "auth:invitation.signIn" }),
+ );
+
+ expect(navigate).toHaveBeenCalledWith({
+ to: "/auth/sign-in",
+ search: { invitationId: "invitation-1", email: "[email protected]" },
+ });
+ });
+});
diff --git a/apps/web/src/routes/invitation/accept.$inviteId.tsx b/apps/web/src/routes/invitation/accept.$inviteId.tsx
index 5412d2834..30975db05 100644
--- a/apps/web/src/routes/invitation/accept.$inviteId.tsx
+++ b/apps/web/src/routes/invitation/accept.$inviteId.tsx
@@ -10,6 +10,7 @@ import {
Clock,
Loader2,
LogIn,
+ UserPlus,
Users,
XCircle,
} from "lucide-react";
@@ -92,6 +93,17 @@ function AcceptInvitation() {
});
};
+ // Invitees without an account need the sign-up page, not sign-in: it is the
+ // only flow that forwards the invitation id, which is what allows account
+ // creation on instances running with DISABLE_REGISTRATION=true.
+ const handleCreateAccount = () => {
+ const email = invitationData?.invitation?.email;
+ navigate({
+ to: "/auth/sign-up",
+ search: { invitationId: inviteId, email },
+ });
+ };
+
if (isLoading) {
return (
<>
@@ -276,12 +288,17 @@ function AcceptInvitation() {
/>
</p>
<p className="text-sm text-muted-foreground">
- {t("auth:invitation.signInToAccept")}
+ {t("auth:invitation.createAccountOrSignIn")}
</p>
</div>
<div className="space-y-3 pt-2">
- <Button onClick={handleSignIn} className="w-full">
+ <Button onClick={handleCreateAccount} className="w-full">
+ <UserPlus className="w-4 h-4 mr-2" />
+ {t("auth:invitation.createAccount")}
+ </Button>
+
+ <Button onClick={handleSignIn} variant="outline" className="w-full">
<LogIn className="w-4 h-4 mr-2" />
{t("auth:invitation.signIn")}
</Button>
diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts
index b988b49c2..b7de87a9e 100644
--- a/apps/web/vite.config.ts
+++ b/apps/web/vite.config.ts
@@ -11,7 +11,11 @@ export default defineConfig({
},
base: "/",
plugins: [
- tanstackRouter({ autoCodeSplitting: true }),
+ tanstackRouter({
+ autoCodeSplitting: true,
+ // Keep co-located route tests out of the generated route tree.
+ routeFileIgnorePattern: "\\.test\\.tsx?$",
+ }),
tailwindcss(),
react({
babel: {
diff --git a/i18n/de-DE.json b/i18n/de-DE.json
index d5a0e9e28..06ee3c17e 100644
--- a/i18n/de-DE.json
+++ b/i18n/de-DE.json
@@ -246,7 +246,8 @@
"joinWorkspace": "{{workspaceName}} beitreten",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> hat dich eingeladen, ihrem Workspace beizutreten.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> hat dich eingeladen, ihrem Workspace auf Kaneo beizutreten.",
- "signInToAccept": "Melde dich an, um die Einladung anzunehmen.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Wird angenommen...",
"acceptInvitation": "Einladung annehmen",
"goToDashboard": "Zum Dashboard",
diff --git a/i18n/el-GR.json b/i18n/el-GR.json
index eb8161b47..caa3b3795 100644
--- a/i18n/el-GR.json
+++ b/i18n/el-GR.json
@@ -246,7 +246,8 @@
"joinWorkspace": "Συμμετοχή στο {{workspaceName}}",
"inviteBodySignedIn": "Ο/Η <inviter>{{inviterName}}</inviter> σας προσκάλεσε να συμμετάσχετε στον χώρο εργασίας του/της.",
"inviteBodySignedOut": "Ο/Η <inviter>{{inviterName}}</inviter> σας προσκάλεσε να συμμετάσχετε στον χώρο εργασίας του/της στο Kaneo.",
- "signInToAccept": "Συνδεθείτε για να αποδεχτείτε αυτήν την πρόσκληση.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Γίνεται αποδοχή...",
"acceptInvitation": "Αποδοχή πρόσκλησης",
"goToDashboard": "Μετάβαση στον πίνακα ελέγχου",
diff --git a/i18n/en-US.json b/i18n/en-US.json
index 8ad5cf085..7cb0212b9 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -248,7 +248,8 @@
"joinWorkspace": "Join {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> has invited you to join their workspace.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> has invited you to join their workspace on Kaneo.",
- "signInToAccept": "Sign in to accept this invitation.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Accepting...",
"acceptInvitation": "Accept Invitation",
"goToDashboard": "Go to Dashboard",
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index c0369b91b..29a290a7b 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -245,7 +245,8 @@
"joinWorkspace": "Unirse a {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> te ha invitado a unirse a su espacio de trabajo.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> te ha invitado a unirse a su espacio de trabajo en Kaneo.",
- "signInToAccept": "Inicia sesión para aceptar esta invitación.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Aceptando...",
"acceptInvitation": "Aceptar invitación",
"goToDashboard": "Ir al Panel de Control",
diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json
index 26dbb5272..9beda5110 100644
--- a/i18n/fr-FR.json
+++ b/i18n/fr-FR.json
@@ -248,7 +248,8 @@
"joinWorkspace": "Rejoindre {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> vous a invité à rejoindre son espace de travail.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> vous a invité à rejoindre son espace de travail sur Kaneo.",
- "signInToAccept": "Connectez-vous pour accepter cette invitation.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Acceptation...",
"acceptInvitation": "Accepter l'invitation",
"goToDashboard": "Aller au tableau de bord",
diff --git a/i18n/id-ID.json b/i18n/id-ID.json
index 73b2f57f3..9aafd00c1 100644
--- a/i18n/id-ID.json
+++ b/i18n/id-ID.json
@@ -248,7 +248,8 @@
"joinWorkspace": "Gabung {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> mengundang Anda untuk bergabung ke ruang kerjanya.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> mengundang Anda untuk bergabung ke ruang kerjanya di Kaneo.",
- "signInToAccept": "Masuk untuk menerima undangan ini.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Menerima...",
"acceptInvitation": "Terima Undangan",
"goToDashboard": "Buka Dasbor",
diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json
index f83503291..d40cf3691 100644
--- a/i18n/ko-KR.json
+++ b/i18n/ko-KR.json
@@ -246,7 +246,8 @@
"joinWorkspace": "{{workspaceName}} 참여",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter>님이 워크스페이스에 초대했습니다.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter>님이 Kaneo 워크스페이스에 초대했습니다.",
- "signInToAccept": "이 초대를 수락하려면 로그인하세요.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "수락 중...",
"acceptInvitation": "초대 수락",
"goToDashboard": "대시보드로 이동",
diff --git a/i18n/mk-MK.json b/i18n/mk-MK.json
index b95b07ee6..3a803129c 100644
--- a/i18n/mk-MK.json
+++ b/i18n/mk-MK.json
@@ -246,7 +246,8 @@
"joinWorkspace": "Приклучи се на {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> те покани да се приклучиш на нивниот работен простор.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> те покани да се приклучиш на нивниот работен простор на Kaneo.",
- "signInToAccept": "Најави се за да ја прифатиш поканата.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Се прифаќа...",
"acceptInvitation": "Прифати покана",
"goToDashboard": "Оди на контролна табла",
diff --git a/i18n/nl-NL.json b/i18n/nl-NL.json
index d2601e62f..bf12bb7ba 100644
--- a/i18n/nl-NL.json
+++ b/i18n/nl-NL.json
@@ -245,7 +245,8 @@
"joinWorkspace": "Deelnemen aan {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> heeft je uitgenodigd voor hun werkruimte.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> heeft je uitgenodigd om deel te nemen aan hun werkruimte op Kaneo.",
- "signInToAccept": "Log in om deze uitnodiging te accepteren.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Accepteren...",
"acceptInvitation": "Uitnodiging accepteren",
"goToDashboard": "Naar dashboard",
diff --git a/i18n/ru-RU.json b/i18n/ru-RU.json
index 1796e38c9..3104312ef 100644
--- a/i18n/ru-RU.json
+++ b/i18n/ru-RU.json
@@ -246,7 +246,8 @@
"joinWorkspace": "Присоединиться к {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> приглашает вас присоединиться к рабочей области.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> приглашает вас присоединиться к рабочей области в Kaneo.",
- "signInToAccept": "Войдите, чтобы принять приглашение.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Принятие...",
"acceptInvitation": "Принять приглашение",
"goToDashboard": "Перейти к панели управления",
diff --git a/i18n/schema.json b/i18n/schema.json
index 59c87e086..9218d8512 100644
--- a/i18n/schema.json
+++ b/i18n/schema.json
@@ -977,7 +977,10 @@
"inviteBodySignedOut": {
"type": "string"
},
- "signInToAccept": {
+ "createAccountOrSignIn": {
+ "type": "string"
+ },
+ "createAccount": {
"type": "string"
},
"accepting": {
@@ -1029,7 +1032,8 @@
"joinWorkspace",
"inviteBodySignedIn",
"inviteBodySignedOut",
- "signInToAccept",
+ "createAccountOrSignIn",
+ "createAccount",
"accepting",
"acceptInvitation",
"goToDashboard",
diff --git a/i18n/tr-TR.json b/i18n/tr-TR.json
index 37c7a1483..94085c7da 100644
--- a/i18n/tr-TR.json
+++ b/i18n/tr-TR.json
@@ -247,7 +247,8 @@
"joinWorkspace": "{{workspaceName}} çalışma alanına katıl",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> sizi çalışma alanına katılmaya davet etti.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> sizi Kaneo üzerindeki çalışma alanına katılmaya davet etti.",
- "signInToAccept": "Bu daveti kabul etmek için giriş yapın.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Kabul ediliyor...",
"acceptInvitation": "Daveti Kabul Et",
"goToDashboard": "Panele Git",
diff --git a/i18n/uk-UA.json b/i18n/uk-UA.json
index a0320e88b..05ec8ab39 100644
--- a/i18n/uk-UA.json
+++ b/i18n/uk-UA.json
@@ -246,7 +246,8 @@
"joinWorkspace": "Приєднатися до {{workspaceName}}",
"inviteBodySignedIn": "<inviter>{{inviterName}}</inviter> запросив вас приєднатися до свого робочого простору.",
"inviteBodySignedOut": "<inviter>{{inviterName}}</inviter> запросив вас приєднатися до свого робочого простору в Kaneo.",
- "signInToAccept": "Увійдіть, щоб прийняти це запрошення.",
+ "createAccountOrSignIn": "Create an account to accept this invitation, or sign in if you already have one.",
+ "createAccount": "Create Account",
"accepting": "Приймається...",
"acceptInvitation": "Прийняти запрошення",
"goToDashboard": "Перейти до панелі керування",