Fix for authentication data flow
parent
ed6f256fb3
commit
002950d708
|
|
@ -48,6 +48,9 @@ const me = (state = initialState, action) =>
|
|||
|
||||
case 'ADD_ROLE':
|
||||
{
|
||||
if (state.roles.includes(action.payload.role))
|
||||
return state;
|
||||
|
||||
const roles = [ ...state.roles, action.payload.role ];
|
||||
|
||||
return { ...state, roles };
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class Peer extends EventEmitter
|
|||
{
|
||||
constructor({ id, roomId, socket })
|
||||
{
|
||||
logger.info('constructor() [id:"%s", socket:"%s"]', id, socket.id);
|
||||
logger.info('constructor() [id:"%s"]', id);
|
||||
super();
|
||||
|
||||
this._id = id;
|
||||
|
|
@ -59,23 +59,26 @@ class Peer extends EventEmitter
|
|||
transport.close();
|
||||
});
|
||||
|
||||
if (this._socket)
|
||||
this._socket.disconnect(true);
|
||||
if (this.socket)
|
||||
this.socket.disconnect(true);
|
||||
|
||||
this.emit('close');
|
||||
}
|
||||
|
||||
_handlePeer()
|
||||
{
|
||||
this.socket.on('disconnect', () =>
|
||||
if (this.socket)
|
||||
{
|
||||
if (this.closed)
|
||||
return;
|
||||
|
||||
logger.debug('"disconnect" event [id:%s]', this.id);
|
||||
|
||||
this.close();
|
||||
});
|
||||
this.socket.on('disconnect', () =>
|
||||
{
|
||||
if (this.closed)
|
||||
return;
|
||||
|
||||
logger.debug('"disconnect" event [id:%s]', this.id);
|
||||
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get id()
|
||||
|
|
|
|||
|
|
@ -309,42 +309,28 @@ async function setupAuth()
|
|||
{
|
||||
const state = JSON.parse(base64.decode(req.query.state));
|
||||
|
||||
let displayName;
|
||||
let picture;
|
||||
const { peerId, roomId } = state;
|
||||
|
||||
if (req.user != null)
|
||||
{
|
||||
if (req.user.displayName != null)
|
||||
displayName = req.user.displayName;
|
||||
else
|
||||
displayName = '';
|
||||
let peer = peers.get(peerId);
|
||||
|
||||
if (req.user.picture != null)
|
||||
picture = req.user.picture;
|
||||
else
|
||||
picture = '/static/media/buddy.403cb9f6.svg';
|
||||
}
|
||||
if (!peer) // User has no socket session yet, make temporary
|
||||
peer = new Peer({ id: peerId, roomId });
|
||||
|
||||
const peer = peers.get(state.peerId);
|
||||
|
||||
if (peer && peer.roomId !== state.roomId) // The peer is mischievous
|
||||
if (peer && peer.roomId !== roomId) // The peer is mischievous
|
||||
throw new Error('peer authenticated with wrong room');
|
||||
|
||||
peer && (peer.displayName = displayName);
|
||||
peer && (peer.picture = picture);
|
||||
|
||||
if (peer && typeof config.userMapping === 'function')
|
||||
{
|
||||
await config.userMapping({
|
||||
peer,
|
||||
roomId : state.roomId,
|
||||
roomId,
|
||||
userinfo : req.user._userinfo
|
||||
});
|
||||
}
|
||||
|
||||
res.send(loginHelper({
|
||||
displayName,
|
||||
picture
|
||||
displayName : peer.displayName,
|
||||
picture : peer.picture
|
||||
}));
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue