Add redirect to /logout if not loggedin or on subscription errors

This commit is contained in:
Oswaldo Acauan 2017-12-13 15:58:56 -02:00
parent b7fa508d9d
commit d19c127b1f

View File

@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { withRouter } from 'react-router';
import PropTypes from 'prop-types';
import Auth from '/imports/ui/services/auth';
import AppContainer from '/imports/ui/components/app/container';
@ -86,22 +87,29 @@ const SUBSCRIPTIONS_NAME = [
'slides', 'captions', 'breakouts', 'voiceUsers', 'whiteboard-multi-user',
];
const BaseContainer = createContainer(({ params }) => {
const BaseContainer = withRouter(createContainer(({ params, router }) => {
if (params.errorCode) return params;
if (!Auth.loggedIn) {
return {
errorCode: 401,
error: 'You are unauthorized to access this meeting',
};
return router.push('/logout');
}
const credentials = Auth.credentials;
const subscriptionsHandlers = SUBSCRIPTIONS_NAME.map(name => Meteor.subscribe(name, credentials));
const { credentials } = Auth;
const subscriptionErrorHandler = {
onError: (error) => {
console.error(error);
return router.push('/logout');
},
};
const subscriptionsHandlers = SUBSCRIPTIONS_NAME.map(name =>
Meteor.subscribe(name, credentials, subscriptionErrorHandler));
return {
locale: Settings.application.locale,
subscriptionsReady: subscriptionsHandlers.every(handler => handler.ready()),
};
}, Base);
}, Base));
export default BaseContainer;