import type { MetaFunction, LoaderFunctionArgs } from "@remix-run/node"; import { json } from "@remix-run/node"; import { useLoaderData, Link, useSearchParams } from "@remix-run/react"; import { getUserSession } from "~/lib/session.server"; import { accountLinkingService } from "~/lib/account-linking.server"; export const meta: MetaFunction = () => { return [ { title: "GitHub + HuggingFace Account Linking" }, { name: "description", content: "Link your GitHub and HuggingFace accounts" }, ]; }; export async function loader({ request }: LoaderFunctionArgs) { const userSession = await getUserSession(request); const url = new URL(request.url); const error = url.searchParams.get("error"); const details = url.searchParams.get("details"); const message = url.searchParams.get("message"); const cookies = request.headers.get("Cookie") || ""; console.log("Cookie keys available:", cookies.split(";").map(c => c.trim().split("=")[0])); // Get linking stats if available let linkingStats = null; if (userSession) { linkingStats = accountLinkingService.getStats(); } return json({ userSession, error, details, message, linkingStats }); } export default function Index() { const { userSession, error, details, message, linkingStats } = useLoaderData(); const [searchParams] = useSearchParams(); // Determine authentication status const hasGitHub = !!userSession?.github; const hasHuggingFace = !!userSession?.huggingface; const isLinked = userSession?.isLinked || false; return (

Account Linking

Link your GitHub and HuggingFace accounts in one place

{/* Error Messages */} {error && (

Authentication Error

{error === "oauth_failed" && (

OAuth authentication failed.

{details &&

Details: {details}

}
)} {error === "no_code" && "No authorization code received."} {error === "callback_failed" && (

Failed to complete authentication.

{message &&

Error: {message}

}
)} {error === "hf_oauth_not_configured" && (

HuggingFace OAuth is not properly configured.

Please set up the required environment variables.

)} {error === "hf_oauth_failed" && (

HuggingFace authentication failed.

{details &&

Details: {details}

}
)}
)} {/* Main Account Linking Interface */}

Account Status

{/* GitHub Authentication Status */}

GitHub

{hasGitHub ? (
{userSession?.github?.avatar_url && ( {userSession.github.login} )}

{userSession?.github?.name || userSession?.github?.login}

@{userSession?.github?.login}

Disconnect
) : (

Not connected

Connect GitHub
)}
{/* HuggingFace Authentication Status */}

HuggingFace

{hasHuggingFace ? (
{userSession?.huggingface?.avatarUrl && ( {userSession.huggingface.username} )}

{userSession?.huggingface?.fullName || userSession?.huggingface?.username}

@{userSession?.huggingface?.username}

Disconnect
) : (

Not connected

Connect HuggingFace
)}
{/* Account Linking Status */}

Account Linking Status

{isLinked ? 'Linked' : 'Not Linked'}
{isLinked ? (

Your GitHub and HuggingFace accounts are linked!

Linked on: {new Date(userSession?.linkedAt || '').toLocaleString()}

) : (
{hasGitHub && hasHuggingFace ? (

Your accounts are not linked

You have both accounts connected but they couldn't be linked automatically.

This may be because one of these accounts is already linked to another account.

) : (

Connect both your GitHub and HuggingFace accounts to link them.

)}
)}
{/* Stats */} {linkingStats && (

Total linked accounts: {linkingStats.totalLinks}

Last updated: {new Date(linkingStats.lastModified).toLocaleString()}

)}
); }