-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1934 from GluuFederation/admin-ui-1929
feat(admin-ui): logout not working
- Loading branch information
Showing
4 changed files
with
154 additions
and
61 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,33 +1,36 @@ | ||
import React, { useEffect } from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { uuidv4 } from 'Utils/Util' | ||
import { EmptyLayout, Label } from 'Components' | ||
import { logoutUser } from 'Redux/features/logoutSlice' | ||
import { useTranslation } from 'react-i18next' | ||
import React, { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { uuidv4 } from "Utils/Util"; | ||
import { EmptyLayout, Label } from "Components"; | ||
import { logoutUser } from "Redux/features/logoutSlice"; | ||
import { useTranslation } from "react-i18next"; | ||
import { setAuthState } from "../../redux/features/authSlice"; | ||
|
||
function ByeBye() { | ||
const config = useSelector((state) => state.authReducer.config) | ||
const dispatch = useDispatch() | ||
const { t } = useTranslation() | ||
const config = useSelector((state) => state.authReducer.config); | ||
|
||
const dispatch = useDispatch(); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
if (config) { | ||
const state = uuidv4() | ||
const sessionEndpoint = `${config.endSessionEndpoint}?state=${state}&post_logout_redirect_uri=${config.postLogoutRedirectUri}` | ||
window.location.href = sessionEndpoint | ||
dispatch(setAuthState(false)); | ||
if (config && Object.keys(config).length > 0) { | ||
const state = uuidv4(); | ||
const sessionEndpoint = `${config.endSessionEndpoint}?state=${state}&post_logout_redirect_uri=${config.postLogoutRedirectUri}`; | ||
dispatch(logoutUser()); | ||
window.location.href = sessionEndpoint; | ||
} | ||
|
||
dispatch(logoutUser()) | ||
}, []) | ||
}, []); | ||
|
||
return ( | ||
<div className="fullscreen"> | ||
<EmptyLayout.Section center> | ||
<Label style={{ fontSize: '2em', fontWeight: 'bold' }}> | ||
{t('Thanks for using the admin ui')}. | ||
<Label style={{ fontSize: "2em", fontWeight: "bold" }}> | ||
{t("Thanks for using the admin ui")}. | ||
</Label> | ||
</EmptyLayout.Section> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
export default ByeBye | ||
export default ByeBye; |
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,24 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Navigate } from "react-router-dom"; | ||
import { useSelector } from "react-redux"; | ||
|
||
const ProtectedRoute = ({ children }) => { | ||
const isAuthenticated = useSelector( | ||
(state) => state.authReducer.isAuthenticated | ||
); | ||
|
||
if (!isAuthenticated) { | ||
// Redirect to login if the user is not authenticated | ||
return <Navigate to="/" replace />; | ||
} | ||
|
||
// Render the protected content | ||
return children; | ||
}; | ||
|
||
ProtectedRoute.propTypes = { | ||
children: PropTypes.node.isRequired, // Enforce that children must be a React node | ||
}; | ||
|
||
export default ProtectedRoute; |
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