fix: OAuth buttons — fetch authUrl then redirect (SuperOAuth JSON flow)
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 24s

This commit is contained in:
2026-03-15 03:27:00 +01:00
parent 40938be067
commit 94b607c4d0

View File

@@ -22,6 +22,21 @@ export default function LoginPage() {
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [oauthLoading, setOauthLoading] = useState<string | null>(null);
async function handleOAuth(providerId: string) {
if (oauthLoading) return;
setOauthLoading(providerId);
try {
const res = await fetch(`${base}/api/v1/oauth/${providerId}?redirectUrl=${redirectUrl}`);
const data = await res.json() as { success: boolean; data?: { authUrl?: string } };
if (data.data?.authUrl) {
window.location.href = data.data.authUrl;
}
} catch {
setOauthLoading(null);
}
}
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
@@ -89,13 +104,14 @@ export default function LoginPage() {
{/* OAuth providers */}
<div className="flex flex-col gap-2">
{PROVIDERS.map(({ id, label }) => (
<a
<button
key={id}
href={`${base}/api/v1/oauth/${id}?redirectUrl=${redirectUrl}`}
className="flex items-center justify-center rounded border border-od-border bg-od-surface px-4 py-2.5 text-sm text-od-muted transition-colors hover:border-od-accent hover:text-od-accent"
onClick={() => handleOAuth(id)}
disabled={oauthLoading === id}
className="flex items-center justify-center rounded border border-od-border bg-od-surface px-4 py-2.5 text-sm text-od-muted transition-colors hover:border-od-accent hover:text-od-accent disabled:opacity-40"
>
{label}
</a>
{oauthLoading === id ? '…' : label}
</button>
))}
</div>