The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fixed a few more redirect logic
Steven Teyc4f8fde47e9f
diff --git a/app/app/(auth)/login/form.tsx b/app/app/(auth)/login/form.tsxindex a73575be99..3c60fc5855 100644--- a/app/app/(auth)/login/form.tsx+++ b/app/app/(auth)/login/form.tsx@@ -7,8 +7,7 @@ import { useSearchParams } from "next/navigation";import { toast } from "sonner";import Button from "#/ui/button";import { Google } from "@/components/shared/icons";-import { InfoTooltip, SimpleTooltipContent } from "#/ui/tooltip";-import { HOME_DOMAIN } from "#/lib/constants";+import { InfoTooltip } from "#/ui/tooltip";export default function LoginForm() {const searchParams = useSearchParams();@@ -143,13 +142,7 @@ export default function LoginForm() {Project Slug</h2><InfoTooltip- content={- <SimpleTooltipContent- title={`This is your project's unique identifier on Dub. E.g. app.dub.sh/acme is "acme".`}- cta="Learn more."- href={`${HOME_DOMAIN}/help/article/sso`}- />- }+ content={`This is your project's unique identifier on Dub. E.g. app.dub.sh/acme is "acme".`}/></div><inputdiff --git a/app/app/(auth)/register/form.tsx b/app/app/(auth)/register/form.tsxindex 9e46b69eca..1d03c2e27c 100644--- a/app/app/(auth)/register/form.tsx+++ b/app/app/(auth)/register/form.tsx@@ -5,13 +5,17 @@ import { useState } from "react";import { signIn } from "next-auth/react";import { Google } from "@/components/shared/icons";import Button from "#/ui/button";-import { SSOWaitlist } from "#/ui/tooltip";import Link from "next/link";+import { InfoTooltip } from "#/ui/tooltip";+import { toast } from "sonner";export default function RegisterForm() {const searchParams = useSearchParams();const next = searchParams?.get("next");const [clickedGoogle, setClickedGoogle] = useState(false);+ const [showSSOOption, setShowSSOOption] = useState(false);+ const [clickedSSO, setClickedSSO] = useState(false);+return (<div className="flex flex-col space-y-3 bg-gray-50 px-4 py-8 sm:px-16"><Button@@ -25,11 +29,65 @@ export default function RegisterForm() {loading={clickedGoogle}icon={<Google className="h-4 w-4" />}/>- <Button- text="Continue with SAML SSO"- disabled- disabledTooltip={<SSOWaitlist />}- />+ <form+ onSubmit={async (e) => {+ e.preventDefault();+ setClickedSSO(true);+ fetch("/api/auth/saml/verify", {+ method: "POST",+ body: JSON.stringify({ slug: e.currentTarget.slug.value }),+ }).then(async (res) => {+ const { data, error } = await res.json();+ if (error) {+ toast.error(error);+ setClickedSSO(false);+ return;+ }+ await signIn("saml", undefined, {+ tenant: data.projectId,+ product: "Dub",+ });+ });+ }}+ className="flex flex-col space-y-3"+ >+ {showSSOOption && (+ <div>+ <div className="mb-4 mt-1 border-t border-gray-300" />+ <div className="flex items-center space-x-2">+ <h2 className="text-sm font-medium text-gray-900">+ Project Slug+ </h2>+ <InfoTooltip+ content={`This is your project's unique identifier on Dub. E.g. app.dub.sh/acme is "acme".`}+ />+ </div>+ <input+ id="slug"+ name="slug"+ autoFocus+ type="text"+ placeholder="my-team"+ autoComplete="off"+ required+ className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"+ />+ </div>+ )}+ <Button+ text="Continue with SAML SSO"+ variant="secondary"+ {...(!showSSOOption && {+ type: "button",+ onClick: (e) => {+ e.preventDefault();+ setShowSSOOption(true);+ },+ })}+ loading={clickedSSO}+ disabled={clickedGoogle || clickedGoogle}+ />+ </form><p className="text-center text-sm text-gray-500">Already have an account?{" "}<Linkdiff --git a/lib/middleware/app.ts b/lib/middleware/app.tsindex c5e0ed0976..59512ba21f 100644--- a/lib/middleware/app.ts+++ b/lib/middleware/app.ts@@ -37,18 +37,27 @@ export default async function AppMiddleware(req: NextRequest) {path === "/") {// check if the user has an existing project invite, if yes, we skip the onboarding flow- const existingInvite = await conn- ?.execute("SELECT projectId FROM ProjectInvite WHERE email = ?", [- session.email,- ])- .then((res) => res.rows[0] as { projectId: string } | undefined);+ const [existingInvite, existingProject] = [+ await conn+ ?.execute("SELECT projectId FROM ProjectInvite WHERE email = ?", [+ session.email,+ ])+ .then((res) => res.rows[0] as { projectId: string } | undefined),+ await conn+ ?.execute("SELECT projectId FROM ProjectUsers WHERE userId = ?", [+ session.user.id,+ ])+ .then((res) => res.rows[0] as { projectId: string } | undefined),+ ];- // if there's an existing invite- if (existingInvite) {+ // if there's an existing invite or there's an existing project+ if (existingInvite || existingProject) {// get the project slugconst project = await conn?.execute("SELECT slug from Project WHERE id = ?", [- existingInvite.projectId,+ existingInvite+ ? existingInvite.projectId+ : existingProject?.projectId,]).then((res) => res.rows[0] as { slug: string } | undefined);