Without this the bot PAT 403s on POST /orgs/{org}/repos, which is
the single most important operation — creating new project repos
inside the workspace's Gitea org.
Made-with: Cursor
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useSession } from "next-auth/react";
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
import { useEffect, Suspense } from "react";
|
|
import NextAuthComponent from "@/app/components/NextAuthComponent";
|
|
|
|
function deriveWorkspace(email: string): string {
|
|
return email.split("@")[0].toLowerCase().replace(/[^a-z0-9]+/g, "-") + "-account";
|
|
}
|
|
|
|
function AuthPageInner() {
|
|
const { data: session, status } = useSession();
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
|
|
useEffect(() => {
|
|
if (status === "authenticated" && session?.user?.email) {
|
|
const callbackUrl = searchParams.get("callbackUrl");
|
|
// Only follow external callbackUrls we control (Theia subdomain)
|
|
if (callbackUrl && callbackUrl.startsWith("https://theia.vibnai.com")) {
|
|
window.location.href = callbackUrl;
|
|
} else {
|
|
const workspace = deriveWorkspace(session.user.email);
|
|
router.push(`/${workspace}/projects`);
|
|
}
|
|
}
|
|
}, [status, session, router, searchParams]);
|
|
|
|
if (status === "loading") {
|
|
return (
|
|
<div className="justine-auth-inner">
|
|
<div className="justine-auth-loading-wrap">
|
|
<div className="justine-auth-spinner" aria-hidden />
|
|
<p className="justine-auth-loading-text">Loading authentication…</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return <NextAuthComponent />;
|
|
}
|
|
|
|
export default function AuthPage() {
|
|
return (
|
|
<Suspense>
|
|
<AuthPageInner />
|
|
</Suspense>
|
|
);
|
|
}
|