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,13 +22,18 @@ export default (options = {}) => (
registerHooks({ registerHooks({
hydrators: async (req, res) => { hydrators: async (req, res) => {
if (req.channel && !req.user) { if (req.channel) {
if (!validateChannel(joinChannel(req.channel))) {
res.redirect('/');
}
if (!req.user) {
const {name, type} = req.channel; const {name, type} = req.channel;
if (name !== 'anonymous' || type !== 'r') { if (name !== 'anonymous' || type !== 'r') {
res.redirect('/'); res.redirect('/');
return new Promise(() => {}); return new Promise(() => {});
} }
} }
}
return { return {
chat: await appChatState(req, res), chat: await appChatState(req, res),
user: await appUserState(req, res), user: await appUserState(req, res),