744e34663344cd6071523ba4285cc906.json 11 KB
Newer Older
1
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\pages\\\\login\\\\Login.js\",\n    _s = $RefreshSig$();\n\nimport React, { useState } from 'react';\nimport { Redirect } from 'react-router-dom';\nimport { useOktaAuth } from '@okta/okta-react';\nimport \"./Login.css\";\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport signUp from './signUp/SignUp';\nimport config from '../../config';\nimport SignUp from './signUp/SignUp';\nimport PasswordForgotModal from './passwordReset/PasswordForgotModal';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst Login = () => {\n  _s();\n\n  const {\n    authState,\n    oktaAuth\n  } = useOktaAuth();\n  const [sessionToken, setSessionToken] = useState();\n  const [username, setUsername] = useState('');\n  const [password, setPassword] = useState('');\n\n  const handleUsernameChange = e => {\n    setUsername(e.target.value);\n  };\n\n  const handlePasswordChange = e => {\n    setPassword(e.target.value);\n  };\n\n  const userInputData = JSON.stringify({\n    email: `${username}`,\n    password: `${password}`\n  });\n  const loginRequestOptions = {\n    method: 'POST',\n    body: userInputData\n  };\n\n  const handleSignInFormSubmit = e => {\n    e.preventDefault();\n    oktaAuth.signInWithCredentials({\n      username,\n      password\n    }).then(res => {\n      const sessionToken = res.sessionToken;\n      setSessionToken(sessionToken); // sessionToken is a one-use token, so make sure this is only called once\n\n      oktaAuth.signInWithRedirect({\n        sessionToken,\n        originalUri: '/home'\n      });\n    }).catch(err => console.log('Found an error', err));\n  };\n\n  if (sessionToken) {\n    // Hide form while sessionToken is converted into id/access tokens\n    return null;\n  }\n\n  if (!authState || !authState.isAuthenticated) {\n    return /*#__PURE__*/_jsxDEV(\"div\", {\n      className: \"pageContainer\",\n      children: [/*#__PURE__*/_jsxDEV(SignUp, {}, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 57,\n        columnNumber: 9\n      }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n        className: \"signInForm\",\n        children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n          children: \"Sign in to PipIt\"\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 60,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"form\", {\n          onSubmit: handleSignInFormSubmit,\n          children: [/*#__PURE__*/_jsxDEV(\"label\", {\n            children: [\"Email:\", /*#__PURE__*/_jsxDEV(\"input\", {\n              id: \"username\",\n              type: \"text\",\n              value: username,\n              onChange: handleUsernameChange\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 64,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 62,\n            columnNumber: 13\n          }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n            children: [\"Password:\", /*#__PURE__*/_jsxDEV(\"input\", {\n              id: \"password\",\n              type: \"password\",\n              value: password,\n              onChange: handlePasswordChange\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 71,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 69,\n            columnNumber: 13\n          }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n            className: \"formSubmitButton\",\n            type: \"submit\",\n            children: [\"Sign in\\xA0\\xA0\", /*#__PURE__*/_jsxDEV(FontAwesomeIcon, {\n              icon: \"sign-in-alt\"\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 78,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 76,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 61,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(PasswordForgotModal, {}, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 81,\n          columnNumber: 11\n        }, this)]\n      }, void 0, true, {\n        fileName: _jsxFileName,\n        lineNumber: 59,\n        columnNumber: 9\n      }, this)]\n    }, void 0, true, {\n      fileName: _jsxFileName,\n      lineNumber: 56,\n      columnNumber: 7\n    }, this);\n  } else {\n    return /*#__PURE__*/_jsxDEV(Redirect, {\n      to: \"/home\"\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 86,\n      columnNumber: 12\n    }, this);\n  }\n};\n\n_s(Login, \"u8yY6NlW4PSOG6xgLhGhaVL5lVE=\", false, function () {\n  return [useOktaAuth];\n});\n\n_c = Login;\nexport default Login;\n\nvar _c;\n\n$RefreshReg$(_c, \"Login\");","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/pages/login/Login.js"],"names":["React","useState","Redirect","useOktaAuth","FontAwesomeIcon","signUp","config","SignUp","PasswordForgotModal","Login","authState","oktaAuth","sessionToken","setSessionToken","username","setUsername","password","setPassword","handleUsernameChange","e","target","value","handlePasswordChange","userInputData","JSON","stringify","email","loginRequestOptions","method","body","handleSignInFormSubmit","preventDefault","signInWithCredentials","then","res","signInWithRedirect","originalUri","catch","err","console","log","isAuthenticated"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AACA,SAASC,QAAT,QAAyB,kBAAzB;AACA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAO,aAAP;AACA,SAASC,eAAT,QAAgC,gCAAhC;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,OAAOC,MAAP,MAAmB,cAAnB;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,OAAOC,mBAAP,MAAgC,qCAAhC;;;AAEA,MAAMC,KAAK,GAAG,MAAM;AAAA;;AAClB,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA0BR,WAAW,EAA3C;AACA,QAAM,CAACS,YAAD,EAAeC,eAAf,IAAkCZ,QAAQ,EAAhD;AAEA,QAAM,CAACa,QAAD,EAAWC,WAAX,IAA0Bd,Q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react-router-dom'\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport \"./Login.css\"\r\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\r\nimport signUp from './signUp/SignUp';\r\nimport config from '../../config';\r\nimport SignUp from './signUp/SignUp';\r\nimport PasswordForgotModal from './passwordReset/PasswordForgotModal';\r\n\r\nconst Login = () => {\r\n  const { authState, oktaAuth } = useOktaAuth();\r\n  const [sessionToken, setSessionToken] = useState()\r\n\r\n  const [username, setUsername] = useState('');\r\n  const [password, setPassword] = useState('');\r\n\r\n  const handleUsernameChange = (e) => {\r\n    setUsername(e.target.value);\r\n  };\r\n\r\n  const handlePasswordChange = (e) => {\r\n    setPassword(e.target.value)\r\n  }\r\n\r\n  const userInputData = JSON.stringify({\r\n    email: `${username}`,\r\n    password: `${password}`\r\n  })\r\n\r\n  const loginRequestOptions = {\r\n    method: 'POST',\r\n    body: userInputData\r\n  };\r\n\r\n  const handleSignInFormSubmit = (e) => {\r\n    e.preventDefault();\r\n\r\n    oktaAuth.signInWithCredentials({ username, password })\r\n      .then(res => {\r\n        const sessionToken = res.sessionToken;\r\n        setSessionToken(sessionToken);\r\n        // sessionToken is a one-use token, so make sure this is only called once\r\n        oktaAuth.signInWithRedirect({ sessionToken, originalUri: '/home' });\r\n      })\r\n      .catch(err => console.log('Found an error', err));\r\n  };\r\n\r\n  if (sessionToken) {\r\n    // Hide form while sessionToken is converted into id/access tokens\r\n    return null;\r\n  }\r\n\r\n  if (!authState || !authState.isAuthenticated) {\r\n    return (\r\n      <div className=\"pageContainer\">\r\n        <SignUp />\r\n\r\n        <div className=\"signInForm\">\r\n          <h2>Sign in to PipIt</h2>\r\n          <form onSubmit={handleSignInFormSubmit}>\r\n            <label>\r\n              Email:\r\n              <input\r\n                id=\"username\" type=\"text\"\r\n                value={username}\r\n                onChange={handleUsernameChange} />\r\n            </label>\r\n            <label>\r\n              Password:\r\n              <input\r\n                id=\"password\" type=\"password\"\r\n                value={password}\r\n                onChange={handlePasswordChange} />\r\n            </label>\r\n            <button className=\"formSubmitButton\" type=\"submit\">\r\n              Sign in&nbsp;&nbsp;\r\n              <FontAwesomeIcon icon=\"sign-in-alt\"></FontAwesomeIcon>\r\n            </button>\r\n          </form>\r\n          <PasswordForgotModal />\r\n        </div>\r\n      </div>\r\n    )\r\n  } else {\r\n    return <Redirect to=\"/home\" />\r\n  }\r\n}\r\n\r\nexport default Login"]},"metadata":{},"sourceType":"module"}