-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] Optimizations/react (#186)
* Replaced the lodash module with submodules * Using lazy imports of heavy modules * Replaced the old authorization verification system with PrivateRoute * Dynamic import of all paths * Minifying the syntax highlighting library * Added missing imports * Added expires to head meta * Don't force the code to follow unnecessary redirects * Kawanaao accept CLA --------- Co-authored-by: Yann S <[email protected]>
- Loading branch information
Showing
42 changed files
with
130 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"contributors": ["azukaar", "jwr1", "Jogai", "InterN0te", "catmandx", "revam"], | ||
"contributors": ["azukaar", "jwr1", "Jogai", "InterN0te", "catmandx", "revam", "Kawanaao"], | ||
"message": "We require contributors to sign our [Contributor License Agreement](https://github.com/azukaar/Cosmos-Server/blob/master/cla.md). In order for us to review and merge your code, add yourself to the .clabot file as contributor, as a way of signing the CLA." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Suspense } from "react" | ||
import { Await, Navigate } from "react-router" | ||
import isLoggedIn from "./isLoggedIn" | ||
|
||
function PrivateRoute({ children }) { | ||
return <Suspense> | ||
<Await resolve={isLoggedIn()}> | ||
{authStatus => { | ||
switch (authStatus) { | ||
case "OK": return children | ||
default: return <Navigate to={authStatus} replace /> | ||
} | ||
}} | ||
</Await> | ||
</Suspense> | ||
} | ||
|
||
export default PrivateRoute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
|
||
import * as API from './api'; | ||
import { useEffect } from 'react'; | ||
import { redirectToLocal } from './utils/indexs'; | ||
|
||
const IsLoggedIn = () => useEffect(() => { | ||
async function isLoggedIn() { | ||
const urlSearch = encodeURIComponent(window.location.search); | ||
const redirectToURL = (window.location.pathname + urlSearch); | ||
const data = await API.auth.me(); | ||
|
||
API.auth.me().then((data) => { | ||
if(data.status != 'OK') { | ||
if(data.status == 'NEW_INSTALL') { | ||
redirectToLocal('/cosmos-ui/newInstall'); | ||
} else if (data.status == 'error' && data.code == "HTTP004") { | ||
redirectToLocal('/cosmos-ui/login?redirect=' + redirectToURL); | ||
} else if (data.status == 'error' && data.code == "HTTP006") { | ||
redirectToLocal('/cosmos-ui/loginmfa?redirect=' + redirectToURL); | ||
} else if (data.status == 'error' && data.code == "HTTP007") { | ||
redirectToLocal('/cosmos-ui/newmfa?redirect=' + redirectToURL); | ||
} | ||
} | ||
}) | ||
}, []); | ||
if (data.status == 'NEW_INSTALL') { | ||
return '/cosmos-ui/newInstall'; | ||
} else if (data.status == 'error' && data.code == "HTTP004") { | ||
return '/cosmos-ui/login?redirect=' + redirectToURL; | ||
} else if (data.status == 'error' && data.code == "HTTP006") { | ||
return '/cosmos-ui/loginmfa?redirect=' + redirectToURL; | ||
} else if (data.status == 'error' && data.code == "HTTP007") { | ||
return '/cosmos-ui/newmfa?redirect=' + redirectToURL; | ||
} else if (data.status == 'OK') { | ||
return data.status | ||
} else { | ||
console.warn(`Status "${data.status}" does not have a navigation handler, will be interpreted as OK!`) | ||
return 'OK' | ||
} | ||
}; | ||
|
||
export default IsLoggedIn; | ||
export default isLoggedIn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.