feat: redirect to root on bad channel
This commit is contained in:
parent
662d8c4880
commit
81ad40520a
|
@ -1,6 +1,8 @@
|
|||
import session from 'express-session';
|
||||
import {registerHooks} from 'scwp';
|
||||
|
||||
import {joinChannel, validateChannel} from '~/common/channel';
|
||||
|
||||
import {appChatState, appUserState, appUsernamesState} from './entry';
|
||||
import createRedisClient from './redis';
|
||||
|
||||
|
@ -20,13 +22,18 @@ export default (options = {}) => (
|
|||
|
||||
registerHooks({
|
||||
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;
|
||||
if (name !== 'anonymous' || type !== 'r') {
|
||||
res.redirect('/');
|
||||
return new Promise(() => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
chat: await appChatState(req, res),
|
||||
user: await appUserState(req, res),
|
||||
|
|
Loading…
Reference in New Issue
Block a user