fix: OAuth buttons — fetch authUrl then redirect (SuperOAuth JSON flow)
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 24s
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 24s
This commit is contained in:
@@ -22,6 +22,21 @@ export default function LoginPage() {
|
|||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
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) {
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -89,13 +104,14 @@ export default function LoginPage() {
|
|||||||
{/* OAuth providers */}
|
{/* OAuth providers */}
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
{PROVIDERS.map(({ id, label }) => (
|
{PROVIDERS.map(({ id, label }) => (
|
||||||
<a
|
<button
|
||||||
key={id}
|
key={id}
|
||||||
href={`${base}/api/v1/oauth/${id}?redirectUrl=${redirectUrl}`}
|
onClick={() => handleOAuth(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={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}
|
{oauthLoading === id ? '…' : label}
|
||||||
</a>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user