Skip to content

Commit

Permalink
Merge pull request #973 from Onlineberatung/OB-5443
Browse files Browse the repository at this point in the history
fix: allow join video call with invalid/expired token as anonymous
  • Loading branch information
web-mi authored Aug 3, 2023
2 parents d3e19ff + cff4990 commit 27387ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/api/appointments/getAppointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { endpoints } from '../../resources/scripts/endpoints';
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from '../fetchData';

export const getAppointment = async (
appointmentId: string
appointmentId: string,
skipAuth: boolean = false
): Promise<AppointmentsDataInterface> => {
const url = endpoints.appointmentsServiceBase + '/' + appointmentId;

return fetchData({
url: url,
method: FETCH_METHODS.GET,
responseHandling: [FETCH_ERRORS.CATCH_ALL_WITH_RESPONSE]
responseHandling: [FETCH_ERRORS.CATCH_ALL_WITH_RESPONSE],
skipAuth: skipAuth
});
};
6 changes: 4 additions & 2 deletions src/api/videocalls/getJwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { endpoints } from '../../resources/scripts/endpoints';
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from '../fetchData';

export const getJwt = async (
appointmentId: string
appointmentId: string,
skipAuth: boolean = false
): Promise<VideoCallJwtDataInterface> => {
const url = endpoints.videocallServiceBase + '/' + appointmentId + '/jwt';

return fetchData({
url: url,
method: FETCH_METHODS.GET,
responseHandling: [FETCH_ERRORS.CATCH_ALL_WITH_RESPONSE]
responseHandling: [FETCH_ERRORS.CATCH_ALL_WITH_RESPONSE],
skipAuth: skipAuth
});
};
33 changes: 22 additions & 11 deletions src/components/videoConference/VideoConference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const VideoConference = () => {
const [quitted, setQuitted] = useState(false);
const [ready, setReady] = useState(false);
const [rejected, setRejected] = useState(false);
const [skipAuth, setSkipAuth] = useState(false);
const [confirmed, setConfirmed] = useState(status === 'confirmed');
const [appointment, setAppointment] =
useState<AppointmentsDataInterface>(null);
Expand All @@ -61,12 +62,14 @@ const VideoConference = () => {
);

const loadAppointment = useCallback(() => {
return appointmentService.getAppointment(appointmentId).then((res) => {
if (res.status !== appointment?.status) {
setAppointment(res);
}
});
}, [appointment?.status, appointmentId]);
return appointmentService
.getAppointment(appointmentId, skipAuth)
.then((res) => {
if (res.status !== appointment?.status) {
setAppointment(res);
}
});
}, [appointment?.status, appointmentId, skipAuth]);

const [startWatcher, stopWatcher, isWatcherRunning] =
useWatcher(loadAppointment);
Expand Down Expand Up @@ -133,17 +136,25 @@ const VideoConference = () => {
setInitialized(true);

Promise.all([
appointmentService.getAppointment(appointmentId),
videocallsService.getJwt(appointmentId)
appointmentService.getAppointment(appointmentId, skipAuth),
videocallsService.getJwt(appointmentId, skipAuth)
])
.then(([appointment, videoCallJwtData]) => {
setAppointment(appointment);
setVideoCallJwtData(videoCallJwtData);
setReady(true);
})
.catch((e) => console.error(e))
.finally(() => setReady(true));
.catch((e) => {
if (e?.status === 401 && skipAuth === false) {
setSkipAuth(true);
setInitialized(false);
} else {
console.error(e);
setReady(true);
}
});
}
}, [appointmentId, initialized]);
}, [appointmentId, initialized, skipAuth]);

useEffect(() => {
if (appointment?.id && !isModerator() && !isWatcherRunning) {
Expand Down

0 comments on commit 27387ee

Please sign in to comment.