Skip to content
Merged
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
130 changes: 89 additions & 41 deletions src/app/gpushed/cli-login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

import { Suspense, useEffect, useState } from 'react';
import { useSearchParams } from 'next/navigation';
import { Box } from '@mui/material';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import { Box, CircularProgress } from '@mui/material';
import AuthHeader from '@/app/components/auth-header';
import LoadingSpinner from '@/app/components/loading-spinner';
import { GPUSHED_ENDPOINT } from '@/app/constants';
Expand Down Expand Up @@ -70,51 +69,100 @@ function CliLoginContent() {
return <LoadingSpinner showLogo message="Checking your session..." size={48} />;
}

const button =
'px-8 py-4 rounded-lg font-medium transition-all text-lg w-full text-center bg-pink-500 text-white hover:bg-pink-600 disabled:opacity-60';
// Same card and controls as /login, so approving reads as part of signing in.
const primaryButtonClass =
'w-full flex items-center justify-center gap-2 py-4 rounded-lg font-medium transition-all '
+ 'bg-pink-500 text-white hover:bg-pink-600 disabled:opacity-50 disabled:cursor-not-allowed '
+ 'disabled:hover:bg-pink-500';

return (
const card = (children: React.ReactNode) => (
<Box className="min-h-screen bg-bg flex flex-col">
<AuthHeader />
<Box className="flex-1 flex items-center justify-center px-6">
<div className="max-w-[460px] w-full bg-[var(--surface)] border border-[var(--border)] rounded-2xl p-10">
{state === 'approved' ? (
<div className="flex flex-col items-center gap-6">
<CheckCircleIcon sx={{ fontSize: 56, color: 'var(--accent-text)' }} />
<div className="text-center space-y-3">
<h3 className="text-2xl font-semibold text-content">gpushed is signed in</h3>
<p className="text-muted text-sm">Head back to your terminal; you can close this tab.</p>
</div>
</div>
) : !code ? (
<div className="text-center space-y-3">
<h3 className="text-2xl font-semibold text-content">No sign-in code</h3>
<p className="text-muted text-sm">
Run <code className="font-mono">gpushed login</code> in your terminal; it opens this page with its code.
</p>
</div>
) : (
<div className="flex flex-col items-center gap-6">
<div className="text-center space-y-3">
<h3 className="text-2xl font-semibold text-content">Sign in to gpushed?</h3>
<p className="text-muted text-sm">
Approve only if your terminal shows this code{email && <> and you meant to sign in as {email}</>}.
</p>
</div>
<div className="font-mono text-3xl tracking-[0.2em] text-content py-2">{code}</div>
{state === 'error' && <p className="text-sm text-center text-red-500">{error}</p>}
<button type="button" onClick={approve} disabled={state === 'approving'} className={button}>
{state === 'approving' ? 'Approving…' : 'Approve'}
</button>
<p className="text-xs text-center text-muted">
Didn&apos;t run <code className="font-mono">gpushed login</code>? Close this tab; nothing is signed in.
</p>
</div>
)}
</div>
<Box className="flex-1 flex flex-col items-center px-6">
<div className="flex-[2]" aria-hidden />
<Box
sx={{
maxWidth: '460px',
width: '100%',
bgcolor: 'var(--surface-2)',
border: '1px solid var(--border-2)',
borderRadius: '16px',
padding: '40px',
}}
>
{children}
</Box>
<div className="flex-[3]" aria-hidden />
</Box>
</Box>
);

if (state === 'approved') {
return card(
<>
<h1 className="text-3xl font-normal text-content mb-2">gpushed is signed in</h1>
<p className="text-sm text-muted">
Head back to your terminal; you can close this tab.
</p>
</>
);
}

if (!code) {
return card(
<>
<h1 className="text-3xl font-normal text-content mb-2">No sign-in code</h1>
<p className="text-sm text-muted">
Run <span className="text-content font-mono">gpushed login</span> in your terminal; it opens this page with its code.
</p>
</>
);
}

// The code in the same boxes /login uses for emailed codes, dash between groups.
const [first, second] = code.split('-');
const boxes = (group: string) =>
Array.from(group ?? '').map((ch, i) => (
<span
key={i}
className="w-[48px] h-[56px] flex items-center justify-center rounded-lg text-xl font-medium font-mono bg-surface text-content border border-border-2"
>
{ch}
</span>
));

return card(
<>
<h1 className="text-3xl font-normal text-content mb-2">Sign in to gpushed</h1>
<p className="text-sm text-muted mb-8">
Approve only if your terminal shows this code
{email && <> and you meant to sign in as <span className="text-content">{email}</span></>}.
</p>

<Box className="flex justify-center items-center gap-2 mb-6" aria-label={`Sign-in code ${code}`}>
{boxes(first)}
<span className="text-muted text-xl" aria-hidden>–</span>
{boxes(second)}
</Box>

{state === 'error' && (
<Box className="mb-4 p-3 bg-red-900 bg-opacity-20 border border-red-800 rounded-lg">
<p className="text-red-400 text-sm">{error}</p>
</Box>
)}

<button type="button" onClick={approve} disabled={state === 'approving'} className={`${primaryButtonClass} mb-6`}>
{state === 'approving' && <CircularProgress size={18} sx={{ color: 'inherit' }} />}
Approve
</button>

<Box className="text-center">
<p className="text-sm text-muted">
Didn&apos;t run <span className="text-content font-mono">gpushed login</span>? Close this tab; nothing is signed in.
</p>
</Box>
</>
);
}

export default function GpushedCliLogin() {
Expand Down
Loading