mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
1 line
7.1 KiB
JSON
1 line
7.1 KiB
JSON
|
{"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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