0eea3857faab067a1da60aecc79b3f85.json 13.3 KB
Newer Older
1
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\pages\\\\login\\\\Login.jsx\",\n    _s = $RefreshSig$();\n\nimport React, { useState, useEffect, useRef } from 'react';\nimport { Redirect } from 'react-router-dom';\nimport { useOktaAuth } from '@okta/okta-react';\nimport \"./Login.css\";\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport { NavLink } from 'react-router-dom';\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 [forgotPasswordFormVisibilityState, setForgotPasswordFormVisibilityState] = useState(false);\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: 60,\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: 63,\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: 67,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 65,\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: 74,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 72,\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: 81,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 79,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 64,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n          className: \"password-forgot-prompt\",\n          children: /*#__PURE__*/_jsxDEV(\"span\", {\n            children: /*#__PURE__*/_jsxDEV(\"a\", {\n              onClick: setForgotPasswordFormVisibilityState(true),\n              children: \"Forgot password\"\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 86,\n              columnNumber: 15\n            }, this)\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 85,\n            columnNumber: 13\n          }, this)\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 84,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n          className: `modal ${forgotPasswordFormVisibilityState ? \"active\" : \"inactive\"}`,\n          children: /*#__PURE__*/_jsxDEV(PasswordForgotModal, {\n            removeModal: () => setForgotPasswordFormVisibilityState(false)\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 90,\n            columnNumber: 13\n          }, this)\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 89,\n          columnNumber: 11\n        }, this)]\n      }, void 0, true, {\n        fileName: _jsxFileName,\n        lineNumber: 62,\n        columnNumber: 9\n      }, this)]\n    }, void 0, true, {\n      fileName: _jsxFileName,\n      lineNumber: 59,\n      columnNumber: 7\n    }, this);\n  } else {\n    return /*#__PURE__*/_jsxDEV(Redirect, {\n      to: \"/home\"\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 96,\n      columnNumber: 12\n    }, this);\n  }\n};\n\n_s(Login, \"XlNc2CmG/vFxCt8acIKy6LZQ9RM=\", 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.jsx"],"names":["React","useState","useEffect","useRef","Redirect","useOktaAuth","FontAwesomeIcon","NavLink","signUp","config","SignUp","PasswordForgotModal","Login","authState","oktaAuth","sessionToken","setSessionToken","forgotPasswordFormVisibilityState","setForgotPasswordFormVisibilityState","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,EAA0BC,SAA1B,EAAqCC,MAArC,QAAmD,OAAnD;AACA,SAASC,QAAT,QAAyB,kBAAzB;AACA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAO,aAAP;AACA,SAASC,eAAT,QAAgC,gCAAhC;AACA,SAASC,OAAT,QAAwB,kBAAxB;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,MAA0BT,WAAW,EAA3C;AACA,QAAM,CAACU,YAAD,EAAeC,eAAf,IAAkCf,QAAQ,EAAhD;AAEA,QAAM,CAACgB,iCAAD,EAAoCC,oCAApC,IAA4EjB,QAAQ,CAAC,KAAD,CAA1F;AAEA,QAAM,CAACkB,QAAD,EAAWC,WAAX,IAA0BnB,QAAQ,CAAC,EAAD,CAAxC;AACA,QAAM,CAACoB,QAAD,EAAWC,WAAX,IAA0BrB,QAAQ,CAAC,EAAD,CAAxC;;AAEA,QAAMsB,oBAAoB,GAAIC,CAAD,IAAO;AAClCJ,IAAAA,WAAW,CAACI,CAAC,CAACC,MAAF,CAASC,KAAV,CAAX;AACD,GAFD;;AAIA,QAAMC,oBAAoB,GAAIH,CAAD,IAAO;AAClCF,IAAAA,WAAW,CAACE,CAAC,CAACC,MAAF,CAASC,KAAV,CAAX;AACD,GAFD;;AAIA,QAAME,aAAa,GAAGC,IAAI,CAAC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Effect, useRef } from 'react';\r\nimport { Redirect } from 'react-router-dom'\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport \"./Login.css\"\r\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\r\nimport { NavLink } from 'react-router-dom';\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 [forgotPasswordFormVisibilityState, setForgotPasswordFormVisibilityState] = useState(false)\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          <div className=\"password-forgot-prompt\">\r\n            <span>\r\n              <a onClick={setForgotPasswordFormVisibilityState(true)}>Forgot password</a>\r\n            </span>\r\n          </div>\r\n          <div className={`modal ${forgotPasswordFormVisibilityState ? \"active\" : \"inactive\"}`}>\r\n            <PasswordForgotModal removeModal={() => setForgotPasswordFormVisibilityState(false)} />\r\n          </div>\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"}