import Head from 'next/head'; import { useRouter } from 'next/router'; import type { FormEvent } from 'react'; import { useEffect, useRef, useState } from 'react'; export default function Login() { const router = useRouter(); const { id, audience, acsUrl, providerName, relayState } = router.query; const [state, setState] = useState({ username: 'jackson', domain: 'example.com', }); // Set focus to email input on load const emailInp = useRef(null); useEffect(() => { if (emailInp.current) { emailInp.current.focus(); emailInp.current.select(); } }, []); const handleChange = (e: FormEvent): void => { const { name, value } = e.currentTarget; setState({ ...state, [name]: value, }); }; const handleSubmit = async (e: FormEvent) => { e.preventDefault(); const { username, domain } = state; const response = await fetch(`/api/saml/auth`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email: `${username}@${domain}`, id, audience, acsUrl, providerName, relayState, }), }); if (response.ok) { const newHtml = await response.text(); const newDoc = document.open('text/html', 'replace'); newDoc.write(newHtml); newDoc.close(); } else { document.write('Error in getting SAML response'); } }; return (
Mock SAML IdP - Login

Login

); }