Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: use token instead of url in invite/magic link params

Brad Barbine5c0cfc0330c
diff --git a/apps/carbon/app/routes/_public+/confirm-invite.tsx b/apps/carbon/app/routes/_public+/confirm-invite.tsx
index c74bc69cbd..54ff11da25 100644
--- a/apps/carbon/app/routes/_public+/confirm-invite.tsx
+++ b/apps/carbon/app/routes/_public+/confirm-invite.tsx
@@ -1,3 +1,4 @@
+import { SUPABASE_API_URL, VERCEL_URL } from "@carbon/auth";
import { Button as _Button, Heading as _Heading, VStack } from "@carbon/react";
import { useNavigate, useSearchParams } from "@remix-run/react";
import { AnimatePresence, motion } from "framer-motion";
@@ -14,12 +15,19 @@ export default function ConfirmInvite() {
const [params] = useSearchParams();
const navigate = useNavigate();
- const redirectTo = params.get("confirmation_url");
- if (!redirectTo) {
+ const token = params.get("token");
+ if (!token) {
navigate("/");
return null;
}
+ const getConfirmationURL = (token: string) => {
+ const appUrl = VERCEL_URL
+ ? `https://${VERCEL_URL}`
+ : "http://localhost:3000";
+ return `${SUPABASE_API_URL}/auth/v1/verify?token=${token}&type=invite&redirect_to=${appUrl}/callback`;
+ };
+
return (
<AnimatePresence>
<VStack
@@ -62,9 +70,11 @@ export default function ConfirmInvite() {
{...fade}
transition={{ duration: 1, delay: 2.4 }}
size="lg"
- asChild
+ onClick={() => {
+ window.location.href = getConfirmationURL(token);
+ }}
>
- <a href={redirectTo}>Accept Invite</a>
+ Accept Invite
</Button>
</VStack>
</AnimatePresence>
diff --git a/apps/carbon/app/routes/_public+/confirm-magic-link.tsx b/apps/carbon/app/routes/_public+/confirm-magic-link.tsx
index ccc5c61123..b0f4054f38 100644
--- a/apps/carbon/app/routes/_public+/confirm-magic-link.tsx
+++ b/apps/carbon/app/routes/_public+/confirm-magic-link.tsx
@@ -1,3 +1,4 @@
+import { SUPABASE_API_URL, VERCEL_URL } from "@carbon/auth";
import { Button as _Button, Heading as _Heading, VStack } from "@carbon/react";
import { useNavigate, useSearchParams } from "@remix-run/react";
import { AnimatePresence, motion } from "framer-motion";
@@ -14,12 +15,19 @@ export default function ConfirmInvite() {
const [params] = useSearchParams();
const navigate = useNavigate();
- const redirectTo = params.get("confirmation_url");
- if (!redirectTo) {
+ const token = params.get("token");
+ if (!token) {
navigate("/");
return null;
}
+ const getConfirmationURL = (token: string) => {
+ const appUrl = VERCEL_URL
+ ? `https://${VERCEL_URL}`
+ : "http://localhost:3000";
+ return `${SUPABASE_API_URL}/auth/v1/verify?token=${token}&type=magiclink&redirect_to=${appUrl}/callback`;
+ };
+
return (
<AnimatePresence>
<VStack
@@ -62,9 +70,11 @@ export default function ConfirmInvite() {
{...fade}
transition={{ duration: 1, delay: 2.4 }}
size="lg"
- asChild
+ onClick={() => {
+ window.location.href = getConfirmationURL(token);
+ }}
>
- <a href={redirectTo}>Log In</a>
+ Log In
</Button>
</VStack>
</AnimatePresence>
diff --git a/apps/carbon/app/routes/_public+/login.tsx b/apps/carbon/app/routes/_public+/login.tsx
index 98e73d6c04..4f98685476 100644
--- a/apps/carbon/app/routes/_public+/login.tsx
+++ b/apps/carbon/app/routes/_public+/login.tsx
@@ -89,7 +89,7 @@ export default function LoginRoute() {
className="hidden dark:block max-w-[100px] mb-3"
/>
</div>
- <div className="rounded-lg bg-card border border-border shadow-lg p-8 w-[380px]">
+ <div className="rounded-lg md:bg-card md:border md:border-border md:shadow-lg p-8 w-[380px]">
<ValidatedForm
validator={loginValidator}
defaultValues={{ redirectTo }}
diff --git a/packages/database/supabase/templates/invite.html b/packages/database/supabase/templates/invite.html
index 87f8962f19..ea4bf5d10f 100644
--- a/packages/database/supabase/templates/invite.html
+++ b/packages/database/supabase/templates/invite.html
@@ -4,9 +4,9 @@
You have been invited to create a user on CarbonOS. Follow this link to accept
the invite:
</p>
+
<p>
- <a
- href="{{ .SiteURL }}/confirm-invite?confirmation_url={{ .ConfirmationURL }}/callback"
+ <a href="{{ .SiteURL }}/confirm-invite?token={{ .TokenHash }}"
>Accept the invite</a
>
</p>
diff --git a/packages/database/supabase/templates/magic-link.html b/packages/database/supabase/templates/magic-link.html
index 307b6e5cd6..d0526547ad 100644
--- a/packages/database/supabase/templates/magic-link.html
+++ b/packages/database/supabase/templates/magic-link.html
@@ -1,9 +1,7 @@
<h2>Magic Link for CarbonOS</h2>
<p>Follow this link to login:</p>
+
<p>
- <a
- href="{{ .SiteURL }}/confirm-magic-link?confirmation_url={{ .ConfirmationURL }}/callback"
- >Log In</a
- >
+ <a href="{{ .SiteURL }}/confirm-magic-link?token={{ .TokenHash }}">Log In</a>
</p>