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 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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user