{"ast":null,"code":"var _jsxFileName = \"/app/src/Contexts/AuthContextProvider.js\",\n _s = $RefreshSig$();\n\nimport React, { useState, useEffect } from 'react';\nimport { toast } from 'react-toastify';\nimport AuthContext from './AuthContext';\nimport { PostLogin, PostRegister, PostResetPassword, PostRefreshToken } from '../Api/index';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst AuthContextProvider = ({\n children\n}) => {\n _s();\n\n const [user, setUser] = useState();\n const [loading, setLoading] = useState(false);\n useEffect(() => {\n setLoading(true);\n let curTime = Math.round(new Date().getTime() / 1000);\n let user = JSON.parse(localStorage.getItem('user')); // Confirm JWT is set.\n\n if (user && user.jwt) {\n // Check refresh expiry is valid.\n if (user.refresh_exp && user.refresh_exp > curTime) {\n // Check if JWT is still valid\n if (user.exp < curTime) {\n // Refresh if not\n user = RefreshToken(user.refresh_token);\n localStorage.setItem('user', JSON.stringify(user));\n }\n\n setUser(user);\n }\n }\n\n setLoading(false);\n }, []);\n\n const Login = formValues => {\n setLoading(true);\n PostLogin(formValues).then(user => {\n if (user) {\n setUser(user);\n localStorage.setItem('user', JSON.stringify(user));\n }\n\n setLoading(false);\n });\n };\n\n const Register = formValues => {\n setLoading(true);\n return PostRegister(formValues).then(response => {\n setLoading(false);\n });\n };\n\n const ResetPassword = formValues => {\n return PostResetPassword(formValues);\n };\n\n const RefreshToken = refreshToken => {\n return PostRefreshToken(refreshToken);\n };\n\n const Logout = () => {\n localStorage.removeItem(\"user\");\n setUser(null);\n toast.success('Successfully logged out.');\n };\n\n return /*#__PURE__*/_jsxDEV(AuthContext.Provider, {\n value: {\n Logout,\n Login,\n Register,\n ResetPassword,\n RefreshToken,\n loading,\n user\n },\n children: children\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 65,\n columnNumber: 5\n }, this);\n};\n\n_s(AuthContextProvider, \"udfioCKtdRnd7zIxkVR8jRpOGB4=\");\n\n_c = AuthContextProvider;\nexport default AuthContextProvider;\n\nvar _c;\n\n$RefreshReg$(_c, \"AuthContextProvider\");","map":{"version":3,"sources":["/app/src/Contexts/AuthContextProvider.js"],"names":["React","useState","useEffect","toast","AuthContext","PostLogin","PostRegister","PostResetPassword","PostRefreshToken","AuthContextProvider","children","user","setUser","loading","setLoading","curTime","Math","round","Date","getTime","JSON","parse","localStorage","getItem","jwt","refresh_exp","exp","RefreshToken","refresh_token","setItem","stringify","Login","formValues","then","Register","response","ResetPassword","refreshToken","Logout","removeItem","success"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,SAASC,KAAT,QAAsB,gBAAtB;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,SAASC,SAAT,EAAoBC,YAApB,EAAkCC,iBAAlC,EAAqDC,gBAArD,QAA6E,cAA7E;;;AAEA,MAAMC,mBAAmB,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAkB;AAAA;;AAC5C,QAAM,CAACC,IAAD,EAAOC,OAAP,IAAkBX,QAAQ,EAAhC;AACA,QAAM,CAACY,OAAD,EAAUC,UAAV,IAAwBb,QAAQ,CAAC,KAAD,CAAtC;AAEAC,EAAAA,SAAS,CAAC,MAAM;AACdY,IAAAA,UAAU,CAAC,IAAD,CAAV;AACA,QAAIC,OAAO,GAAGC,IAAI,CAACC,KAAL,CAAY,IAAIC,IAAJ,EAAD,CAAaC,OAAb,KAAyB,IAApC,CAAd;AACA,QAAIR,IAAI,GAAGS,IAAI,CAACC,KAAL,CAAWC,YAAY,CAACC,OAAb,CAAqB,MAArB,CAAX,CAAX,CAHc,CAKd;;AACA,QAAIZ,IAAI,IAAIA,IAAI,CAACa,GAAjB,EAAsB;AACpB;AACA,UAAIb,IAAI,CAACc,WAAL,IAAqBd,IAAI,CAACc,WAAL,GAAmBV,OAA5C,EAAsD;AACpD;AACA,YAAIJ,IAAI,CAACe,GAAL,GAAWX,OAAf,EAAwB;AACtB;AACAJ,UAAAA,IAAI,GAAGgB,YA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;AAMA,sBACE,QAAC,WAAD,CAAa,QAAb;AACE,IAAA,KAAK,EAAE;AACLF,MAAAA,MADK;AAELP,MAAAA,KAFK;AAGLG,MAAAA,QAHK;AAILE,MAAAA,aAJK;AAKLT,MAAAA,YALK;AAMLd,MAAAA,OANK;AAOLF,MAAAA;AAPK,KADT;AAAA,cAWGD;AAXH;AAAA;AAAA;AAAA;AAAA,UADF;AAeD,CAzED;;GAAMD,mB;;KAAAA,mB;AA2EN,eAAeA,mBAAf","sourcesContent":["import React, { useState, useEffect } from 'react';\nimport { toast } from 'react-toastify';\nimport AuthContext from './AuthContext';\nimport { PostLogin, PostRegister, PostResetPassword, PostRefreshToken } from '../Api/index';\n\nconst AuthContextProvider = ({ children }) => {\n const [user, setUser] = useState();\n const [loading, setLoading] = useState(false);\n\n useEffect(() => {\n setLoading(true)\n let curTime = Math.round((new Date()).getTime() / 1000);\n let user = JSON.parse(localStorage.getItem('user'));\n\n // Confirm JWT is set.\n if (user && user.jwt) {\n // Check refresh expiry is valid.\n if (user.refresh_exp && (user.refresh_exp > curTime)) {\n // Check if JWT is still valid\n if (user.exp < curTime) {\n // Refresh if not\n user = RefreshToken(user.refresh_token)\n localStorage.setItem('user', JSON.stringify(user));\n }\n \n setUser(user);\n }\n }\n setLoading(false)\n }, []);\n\n const Login = (formValues) => {\n setLoading(true);\n PostLogin(formValues).then(user => {\n if (user) {\n setUser(user);\n localStorage.setItem('user', JSON.stringify(user));\n }\n setLoading(false);\n })\n }\n\n const Register = (formValues) => {\n setLoading(true);\n return PostRegister(formValues).then(response => {\n setLoading(false);\n });\n };\n\n const ResetPassword = (formValues) => {\n return PostResetPassword(formValues);\n }\n\n const RefreshToken = (refreshToken) => {\n return PostRefreshToken(refreshToken);\n }\n\n const Logout = () => {\n localStorage.removeItem(\"user\");\n setUser(null)\n toast.success('Successfully logged out.');\n };\n\n return (\n \n {children}\n \n );\n};\n\nexport default AuthContextProvider;"]},"metadata":{},"sourceType":"module"}