Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ jobs:
DATABASE_URL: ${{ env.DATABASE_URL }}
DATABASE_URL_UNPOOLED: ${{ env.DATABASE_URL_UNPOOLED }}
NEXT_PUBLIC_API_URL: https://${{ env.API_ALIAS }}
NEXT_PUBLIC_WEB_URL: https://${{ env.WEB_ALIAS }}
NEXT_PUBLIC_MARKETING_URL: https://${{ env.MARKETING_ALIAS }}
NEXT_PUBLIC_DOCS_URL: https://${{ env.DOCS_ALIAS }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
Expand All @@ -229,6 +230,7 @@ jobs:
--env DATABASE_URL_UNPOOLED=$DATABASE_URL_UNPOOLED \
--env DESKTOP_AUTH_SECRET=$DESKTOP_AUTH_SECRET \
--env NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL \
--env NEXT_PUBLIC_WEB_URL=$NEXT_PUBLIC_WEB_URL \
--env NEXT_PUBLIC_MARKETING_URL=$NEXT_PUBLIC_MARKETING_URL \
--env NEXT_PUBLIC_DOCS_URL=$NEXT_PUBLIC_DOCS_URL \
--env NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ jobs:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DATABASE_URL_UNPOOLED: ${{ secrets.DATABASE_URL_UNPOOLED }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_WEB_URL: ${{ secrets.NEXT_PUBLIC_WEB_URL }}
NEXT_PUBLIC_MARKETING_URL: ${{ secrets.NEXT_PUBLIC_MARKETING_URL }}
NEXT_PUBLIC_DOCS_URL: ${{ secrets.NEXT_PUBLIC_DOCS_URL }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
Expand All @@ -151,6 +152,7 @@ jobs:
--env DATABASE_URL_UNPOOLED=$DATABASE_URL_UNPOOLED \
--env DESKTOP_AUTH_SECRET=$DESKTOP_AUTH_SECRET \
--env NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL \
--env NEXT_PUBLIC_WEB_URL=$NEXT_PUBLIC_WEB_URL \
--env NEXT_PUBLIC_MARKETING_URL=$NEXT_PUBLIC_MARKETING_URL \
--env NEXT_PUBLIC_DOCS_URL=$NEXT_PUBLIC_DOCS_URL \
--env NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"use client";

import Image from "next/image";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import { useCallback, useEffect, useState } from "react";

const DESKTOP_PROTOCOL =
process.env.NODE_ENV === "development" ? "superset-dev" : "superset";

export function DesktopAuthSuccess() {
const searchParams = useSearchParams();
const accessToken = searchParams.get("accessToken");
const accessTokenExpiresAt = searchParams.get("accessTokenExpiresAt");
const refreshToken = searchParams.get("refreshToken");
const refreshTokenExpiresAt = searchParams.get("refreshTokenExpiresAt");
const state = searchParams.get("state");
const error = searchParams.get("error");

const [hasAttempted, setHasAttempted] = useState(false);

const hasAllTokens =
accessToken &&
accessTokenExpiresAt &&
refreshToken &&
refreshTokenExpiresAt &&
state;

const desktopUrl = hasAllTokens
? `${DESKTOP_PROTOCOL}://auth/callback?accessToken=${encodeURIComponent(accessToken)}&accessTokenExpiresAt=${encodeURIComponent(accessTokenExpiresAt)}&refreshToken=${encodeURIComponent(refreshToken)}&refreshTokenExpiresAt=${encodeURIComponent(refreshTokenExpiresAt)}&state=${encodeURIComponent(state)}`
: null;

const openDesktopApp = useCallback(() => {
if (!desktopUrl) return;
window.location.href = desktopUrl;
}, [desktopUrl]);

useEffect(() => {
if (error || !desktopUrl || hasAttempted) return;
setHasAttempted(true);
openDesktopApp();
}, [error, desktopUrl, hasAttempted, openDesktopApp]);

if (error) {
return (
<div className="flex flex-col items-center gap-6">
<Image
src="/title.svg"
alt="Superset"
width={140}
height={43}
priority
/>
<p className="text-xl text-muted-foreground">Authentication failed</p>
<p className="text-muted-foreground/70">{error}</p>
</div>
);
}

if (!hasAllTokens) {
return (
<div className="flex flex-col items-center gap-6">
<Image
src="/title.svg"
alt="Superset"
width={140}
height={43}
priority
/>
<p className="text-xl text-muted-foreground">Invalid request</p>
<p className="text-muted-foreground/70">
Missing authentication parameters. Please try again.
</p>
</div>
);
}

return (
<div className="flex flex-col items-center">
<Image src="/title.svg" alt="Superset" width={280} height={86} priority />
<p className="text-xl text-muted-foreground">
Redirecting to the desktop app...
</p>
<div className="flex flex-col items-center gap-2">
{desktopUrl && (
<Link
href={desktopUrl}
className="text-muted-foreground/70 underline decoration-muted-foreground/40 underline-offset-4 transition-colors hover:text-muted-foreground"
>
If you weren&apos;t redirected, click here.
</Link>
)}
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { DesktopAuthSuccess } from "./DesktopAuthSuccess";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Image from "next/image";

export function LoadingFallback() {
return (
<div className="flex flex-col items-center gap-6">
<Image src="/title.svg" alt="Superset" width={140} height={43} priority />
<p className="text-xl text-muted-foreground">Loading...</p>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LoadingFallback } from "./LoadingFallback";
104 changes: 6 additions & 98 deletions apps/web/src/app/auth/desktop/success/page.tsx
Original file line number Diff line number Diff line change
@@ -1,108 +1,16 @@
"use client";

import Image from "next/image";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import { useCallback, useEffect, useState } from "react";
import { Suspense } from "react";

const DESKTOP_PROTOCOL =
process.env.NODE_ENV === "development" ? "superset-dev" : "superset";
import { DesktopAuthSuccess } from "./components/DesktopAuthSuccess";
import { LoadingFallback } from "./components/LoadingFallback";

export default function Page() {
const searchParams = useSearchParams();
const accessToken = searchParams.get("accessToken");
const accessTokenExpiresAt = searchParams.get("accessTokenExpiresAt");
const refreshToken = searchParams.get("refreshToken");
const refreshTokenExpiresAt = searchParams.get("refreshTokenExpiresAt");
const state = searchParams.get("state");
const error = searchParams.get("error");

const [hasAttempted, setHasAttempted] = useState(false);

const hasAllTokens =
accessToken &&
accessTokenExpiresAt &&
refreshToken &&
refreshTokenExpiresAt &&
state;

const desktopUrl = hasAllTokens
? `${DESKTOP_PROTOCOL}://auth/callback?accessToken=${encodeURIComponent(accessToken)}&accessTokenExpiresAt=${encodeURIComponent(accessTokenExpiresAt)}&refreshToken=${encodeURIComponent(refreshToken)}&refreshTokenExpiresAt=${encodeURIComponent(refreshTokenExpiresAt)}&state=${encodeURIComponent(state)}`
: null;

const openDesktopApp = useCallback(() => {
if (!desktopUrl) return;
window.location.href = desktopUrl;
}, [desktopUrl]);

useEffect(() => {
if (error || !desktopUrl || hasAttempted) return;
setHasAttempted(true);
openDesktopApp();
}, [error, desktopUrl, hasAttempted, openDesktopApp]);

if (error) {
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-background p-4">
<div className="flex flex-col items-center gap-6">
<Image
src="/title.svg"
alt="Superset"
width={140}
height={43}
priority
/>
<p className="text-xl text-muted-foreground">Authentication failed</p>
<p className="text-muted-foreground/70">{error}</p>
</div>
</div>
);
}

if (!hasAllTokens) {
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-background p-4">
<div className="flex flex-col items-center gap-6">
<Image
src="/title.svg"
alt="Superset"
width={140}
height={43}
priority
/>
<p className="text-xl text-muted-foreground">Invalid request</p>
<p className="text-muted-foreground/70">
Missing authentication parameters. Please try again.
</p>
</div>
</div>
);
}

return (
<div className="flex min-h-screen flex-col items-center justify-center bg-background p-4">
<div className="flex flex-col items-center">
<Image
src="/title.svg"
alt="Superset"
width={280}
height={86}
priority
/>
<p className="text-xl text-muted-foreground">
Redirecting to the desktop app...
</p>
<div className="flex flex-col items-center gap-2">
{desktopUrl && (
<Link
href={desktopUrl}
className="text-muted-foreground/70 underline decoration-muted-foreground/40 underline-offset-4 transition-colors hover:text-muted-foreground"
>
If you weren&apos;t redirected, click here.
</Link>
)}
</div>
</div>
<Suspense fallback={<LoadingFallback />}>
<DesktopAuthSuccess />
</Suspense>
</div>
);
}