From b64af7afffafbdc5d2e0a10907db70432a89f156 Mon Sep 17 00:00:00 2001 From: Aswin V Date: Tue, 22 Feb 2022 13:48:07 +0530 Subject: [PATCH] Login form submittion --- pages/saml/login.tsx | 71 +++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/pages/saml/login.tsx b/pages/saml/login.tsx index 78837f2..42f8292 100644 --- a/pages/saml/login.tsx +++ b/pages/saml/login.tsx @@ -1,42 +1,71 @@ -import Head from "next/head"; +import Head from 'next/head'; +import { useState } from 'react'; +import type { FormEvent } from 'react'; +import { useRouter } from 'next/router'; export default function Login() { + const router = useRouter(); + const { id, audience, acsUrl, providerName, relayState } = router.query; + const [email, setEmail] = useState('@example.com'); + + const handleChange = (e: FormEvent): void => { + setEmail(e.currentTarget.value); + }; + + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + const response = await fetch(`/api/saml/auth`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, id, audience, acsUrl, providerName, relayState }), + }); + if (response.ok) { + document.write(await response.text()); + } else { + document.write('Error in getting SAML response'); + } + }; + return ( -
+
Mock SAML IdP - Login -
-

Login

-
+
+

Login

+
-
-
-