Skip to content

Commit

Permalink
Fix issue with room link throwing error when authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
farhatahmad committed Oct 11, 2023
1 parent 16b8922 commit 6f74478
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/javascript/RootBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React from 'react';
import { useRouteError } from 'react-router-dom';
import DefaultErrorPage from './components/errors/DefaultErrorPage';
import NotFoundPage from './components/errors/NotFoundPage';
import ForbiddenRouter from './routes/ForbiddenRouter';

export default function RootBoundary() {
const error = useRouteError();
Expand All @@ -26,6 +27,8 @@ export default function RootBoundary() {
switch (status) {
case 404:
return <NotFoundPage />;
case 403:
return <ForbiddenRouter />;
default:
return <DefaultErrorPage />;
}
Expand Down
12 changes: 2 additions & 10 deletions app/javascript/components/rooms/room/Room.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import React from 'react';
import {
Stack, Button, Col, Row,
} from 'react-bootstrap';
import {
Link, Navigate, useLocation, useParams,
} from 'react-router-dom';
import { Link, useParams } from 'react-router-dom';
import { HomeIcon, Square2StackIcon } from '@heroicons/react/24/outline';
import { toast } from 'react-toastify';
import { useTranslation } from 'react-i18next';
Expand All @@ -39,23 +37,17 @@ export default function Room() {
const { t } = useTranslation();
const { friendlyId } = useParams();
const {
isLoading: isRoomLoading, isError, data: room, error,
isLoading: isRoomLoading, data: room,
} = useRoom(friendlyId);
const startMeeting = useStartMeeting(friendlyId);
const currentUser = useAuth();
const location = useLocation();
const localizedTime = localizeDayDateTimeString(room?.last_session, currentUser?.language);

function copyInvite() {
navigator.clipboard.writeText(`${window.location}/join`);
toast.success(t('toast.success.room.copied_meeting_url'));
}

// Custom logic to redirect from Rooms page to join page if this isnt the users room and they're not allowed to view it
if (isError && error.response.status === 403) {
return <Navigate to={`${location.pathname}/join`} />;
}

return (
<>
<Title>{room?.name}</Title>
Expand Down
30 changes: 30 additions & 0 deletions app/javascript/routes/ForbiddenRouter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
//
// Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below).
//
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free Software
// Foundation; either version 3.0 of the License, or (at your option) any later
// version.
//
// Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along
// with Greenlight; if not, see <http://www.gnu.org/licenses/>.

import React from 'react';
import { Navigate } from 'react-router-dom';
import DefaultErrorPage from '../components/errors/DefaultErrorPage';

export default function ForbiddenRouter() {
const regex = /rooms\/(\w{3}-\w{3}-\w{3})(-\w{3})?/;
const match = window.location.pathname.match(regex);

if (match) {
return <Navigate to={`${match[0]}/join`} />;
}

return <DefaultErrorPage />;
}

0 comments on commit 6f74478

Please sign in to comment.