Fix for authentication data flow

auto_join_3.3
Håvar Aambø Fosstveit 2020-03-23 14:44:12 +01:00
parent ed6f256fb3
commit 002950d708
3 changed files with 25 additions and 33 deletions

View File

@ -48,6 +48,9 @@ const me = (state = initialState, action) =>
case 'ADD_ROLE': case 'ADD_ROLE':
{ {
if (state.roles.includes(action.payload.role))
return state;
const roles = [ ...state.roles, action.payload.role ]; const roles = [ ...state.roles, action.payload.role ];
return { ...state, roles }; return { ...state, roles };

View File

@ -8,7 +8,7 @@ class Peer extends EventEmitter
{ {
constructor({ id, roomId, socket }) constructor({ id, roomId, socket })
{ {
logger.info('constructor() [id:"%s", socket:"%s"]', id, socket.id); logger.info('constructor() [id:"%s"]', id);
super(); super();
this._id = id; this._id = id;
@ -59,13 +59,15 @@ class Peer extends EventEmitter
transport.close(); transport.close();
}); });
if (this._socket) if (this.socket)
this._socket.disconnect(true); this.socket.disconnect(true);
this.emit('close'); this.emit('close');
} }
_handlePeer() _handlePeer()
{
if (this.socket)
{ {
this.socket.on('disconnect', () => this.socket.on('disconnect', () =>
{ {
@ -77,6 +79,7 @@ class Peer extends EventEmitter
this.close(); this.close();
}); });
} }
}
get id() get id()
{ {

View File

@ -309,42 +309,28 @@ async function setupAuth()
{ {
const state = JSON.parse(base64.decode(req.query.state)); const state = JSON.parse(base64.decode(req.query.state));
let displayName; const { peerId, roomId } = state;
let picture;
if (req.user != null) let peer = peers.get(peerId);
{
if (req.user.displayName != null)
displayName = req.user.displayName;
else
displayName = '';
if (req.user.picture != null) if (!peer) // User has no socket session yet, make temporary
picture = req.user.picture; peer = new Peer({ id: peerId, roomId });
else
picture = '/static/media/buddy.403cb9f6.svg';
}
const peer = peers.get(state.peerId); if (peer && peer.roomId !== roomId) // The peer is mischievous
if (peer && peer.roomId !== state.roomId) // The peer is mischievous
throw new Error('peer authenticated with wrong room'); throw new Error('peer authenticated with wrong room');
peer && (peer.displayName = displayName);
peer && (peer.picture = picture);
if (peer && typeof config.userMapping === 'function') if (peer && typeof config.userMapping === 'function')
{ {
await config.userMapping({ await config.userMapping({
peer, peer,
roomId : state.roomId, roomId,
userinfo : req.user._userinfo userinfo : req.user._userinfo
}); });
} }
res.send(loginHelper({ res.send(loginHelper({
displayName, displayName : peer.displayName,
picture picture : peer.picture
})); }));
} }
); );