Skip to content
Snippets Groups Projects

Authentication and major rewriting

Merged Brett Choquet requested to merge feature/authentication into develop
Files
2
@@ -15,7 +15,7 @@ import Policies from '../../pages/policies';
import Groups from '../../pages/groups/Groups';
import { useLayoutState } from '../../context/LayoutContext';
import { useAuth } from 'react-oidc-context';
import { findUserBySub } from '../../services/GatekeeperService';
import { createUser, findUserBySub } from '../../services/GatekeeperService';
const ProtectedRoute = ({ isAllowed, redirectPath = '/forbidden', path, component }) => {
if (!isAllowed) {
@@ -33,7 +33,19 @@ function Layout(props) {
useEffect(() => {
const fetchUser = async (sub) => {
const user = await findUserBySub(sub);
let user = await findUserBySub(sub);
if (!user.id) {
// User registered on Keycloak but not in the database
if (auth.user?.profile?.email) {
const result = await createUser(sub, auth.user?.profile?.email);
if (result) {
user = await findUserBySub(sub);
} else {
auth.signoutRedirect();
}
}
}
setUser(user);
setRoles(user.roles.map((r) => r.role_id));
};
Loading