-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 2545-feat-community-hub-integration
- Loading branch information
Showing
19 changed files
with
568 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { FullScreenLoader } from "@/components/Preloader"; | ||
import { Navigate } from "react-router-dom"; | ||
import paths from "@/utils/paths"; | ||
import useQuery from "@/hooks/useQuery"; | ||
import System from "@/models/system"; | ||
import { AUTH_TIMESTAMP, AUTH_TOKEN, AUTH_USER } from "@/utils/constants"; | ||
|
||
export default function SimpleSSOPassthrough() { | ||
const query = useQuery(); | ||
const redirectPath = query.get("redirectTo") || paths.home(); | ||
const [ready, setReady] = useState(false); | ||
const [error, setError] = useState(null); | ||
|
||
useEffect(() => { | ||
try { | ||
if (!query.get("token")) throw new Error("No token provided."); | ||
|
||
// Clear any existing auth data | ||
window.localStorage.removeItem(AUTH_USER); | ||
window.localStorage.removeItem(AUTH_TOKEN); | ||
window.localStorage.removeItem(AUTH_TIMESTAMP); | ||
|
||
System.simpleSSOLogin(query.get("token")) | ||
.then((res) => { | ||
if (!res.valid) throw new Error(res.message); | ||
|
||
window.localStorage.setItem(AUTH_USER, JSON.stringify(res.user)); | ||
window.localStorage.setItem(AUTH_TOKEN, res.token); | ||
window.localStorage.setItem(AUTH_TIMESTAMP, Number(new Date())); | ||
setReady(res.valid); | ||
}) | ||
.catch((e) => { | ||
setError(e.message); | ||
}); | ||
} catch (e) { | ||
setError(e.message); | ||
} | ||
}, []); | ||
|
||
if (error) | ||
return ( | ||
<div className="w-screen h-screen overflow-hidden bg-sidebar flex items-center justify-center flex-col gap-4"> | ||
<p className="text-white font-mono text-lg">{error}</p> | ||
<p className="text-white/80 font-mono text-sm"> | ||
Please contact the system administrator about this error. | ||
</p> | ||
</div> | ||
); | ||
if (ready) return <Navigate to={redirectPath} />; | ||
|
||
// Loading state by default | ||
return <FullScreenLoader />; | ||
} |
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.