feat: redirect to root on bad channel

This commit is contained in:
cha0s 2020-07-25 08:58:09 -05:00
parent 662d8c4880
commit 81ad40520a

View File

@ -1,6 +1,8 @@
import session from 'express-session'; import session from 'express-session';
import {registerHooks} from 'scwp'; import {registerHooks} from 'scwp';
import {joinChannel, validateChannel} from '~/common/channel';
import {appChatState, appUserState, appUsernamesState} from './entry'; import {appChatState, appUserState, appUsernamesState} from './entry';
import createRedisClient from './redis'; import createRedisClient from './redis';
@ -20,11 +22,16 @@ export default (options = {}) => (
registerHooks({ registerHooks({
hydrators: async (req, res) => { hydrators: async (req, res) => {
if (req.channel && !req.user) { if (req.channel) {
const {name, type} = req.channel; if (!validateChannel(joinChannel(req.channel))) {
if (name !== 'anonymous' || type !== 'r') {
res.redirect('/'); res.redirect('/');
return new Promise(() => {}); }
if (!req.user) {
const {name, type} = req.channel;
if (name !== 'anonymous' || type !== 'r') {
res.redirect('/');
return new Promise(() => {});
}
} }
} }
return { return {