mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-16 21:24:19 +00:00
force login if not logged when navigating to frontend w/ burnettk
This commit is contained in:
parent
bd6e1f2ebe
commit
7dd2e81048
@ -13,6 +13,7 @@ import AdminRoutes from './routes/AdminRoutes';
|
|||||||
import { ErrorForDisplay } from './interfaces';
|
import { ErrorForDisplay } from './interfaces';
|
||||||
|
|
||||||
import { AbilityContext } from './contexts/Can';
|
import { AbilityContext } from './contexts/Can';
|
||||||
|
import UserService from './services/UserService';
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [errorMessage, setErrorMessage] = useState<ErrorForDisplay | null>(
|
const [errorMessage, setErrorMessage] = useState<ErrorForDisplay | null>(
|
||||||
@ -24,6 +25,11 @@ export default function App() {
|
|||||||
[errorMessage]
|
[errorMessage]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!UserService.isLoggedIn()) {
|
||||||
|
UserService.doLogin();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const ability = defineAbility(() => {});
|
const ability = defineAbility(() => {});
|
||||||
|
|
||||||
let errorTag = null;
|
let errorTag = null;
|
||||||
|
@ -24,6 +24,7 @@ import UserService from '../services/UserService';
|
|||||||
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
|
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
|
||||||
import { PermissionsToCheck } from '../interfaces';
|
import { PermissionsToCheck } from '../interfaces';
|
||||||
import { usePermissionFetcher } from '../hooks/PermissionService';
|
import { usePermissionFetcher } from '../hooks/PermissionService';
|
||||||
|
import { UnauthenticatedError } from '../services/HttpService';
|
||||||
|
|
||||||
// for ref: https://react-bootstrap.github.io/components/navbar/
|
// for ref: https://react-bootstrap.github.io/components/navbar/
|
||||||
export default function NavigationBar() {
|
export default function NavigationBar() {
|
||||||
@ -39,6 +40,11 @@ export default function NavigationBar() {
|
|||||||
const [activeKey, setActiveKey] = useState<string>('');
|
const [activeKey, setActiveKey] = useState<string>('');
|
||||||
|
|
||||||
const { targetUris } = useUriListForPermissions();
|
const { targetUris } = useUriListForPermissions();
|
||||||
|
|
||||||
|
// App.jsx forces login (which redirects to keycloak) so we should never get here if we're not logged in.
|
||||||
|
if (UserService.isLoggedIn()) {
|
||||||
|
throw new UnauthenticatedError('You must be authenticated to do this.');
|
||||||
|
}
|
||||||
const permissionRequestData: PermissionsToCheck = {
|
const permissionRequestData: PermissionsToCheck = {
|
||||||
[targetUris.authenticationListPath]: ['GET'],
|
[targetUris.authenticationListPath]: ['GET'],
|
||||||
[targetUris.messageInstanceListPath]: ['GET'],
|
[targetUris.messageInstanceListPath]: ['GET'],
|
||||||
@ -135,6 +141,9 @@ export default function NavigationBar() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const headerMenuItems = () => {
|
const headerMenuItems = () => {
|
||||||
|
if (!UserService.isLoggedIn()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HeaderMenuItem href="/" isCurrentPage={isActivePage('/')}>
|
<HeaderMenuItem href="/" isCurrentPage={isActivePage('/')}>
|
||||||
|
@ -26,7 +26,7 @@ type backendCallProps = {
|
|||||||
postBody?: any;
|
postBody?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnauthenticatedError extends Error {
|
export class UnauthenticatedError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(message);
|
super(message);
|
||||||
this.name = 'UnauthenticatedError';
|
this.name = 'UnauthenticatedError';
|
||||||
|
@ -27,8 +27,8 @@ const doLogout = () => {
|
|||||||
const idToken = getIdToken();
|
const idToken = getIdToken();
|
||||||
localStorage.removeItem('jwtAccessToken');
|
localStorage.removeItem('jwtAccessToken');
|
||||||
localStorage.removeItem('jwtIdToken');
|
localStorage.removeItem('jwtIdToken');
|
||||||
const redirctUrl = `${window.location.origin}/`;
|
const redirectUrl = `${window.location.origin}`;
|
||||||
const url = `${BACKEND_BASE_URL}/logout?redirect_url=${redirctUrl}&id_token=${idToken}`;
|
const url = `${BACKEND_BASE_URL}/logout?redirect_url=${redirectUrl}&id_token=${idToken}`;
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user