1
votes

I am using Flask-Login to manage users on my app, and I also have the user joining a room when they login.

A message is emitted from the front end for the user to join a room after the login is complete.

#User Room
@socketio.on('joinUserRoom')
@login_required
def join_user_room():
    room=current_user.slug
    join_room(room)

The problem is that this login_required is never validated. I get failed with unauthorized. Even though the user just logged in. When I remove @login_required and put a print(current_user) in I get anonymous user mixin as a result.

('CURRENT USER JOIN ROOM', <flask_login.AnonymousUserMixin object at 0x7ff40410fcd0>)

I have tried a bunch of crazy stuff but nothing seems to work, any ideas?

1

1 Answers

0
votes

try to use namespace ,

#User Room
@socketio.on('joinUserRoom', namespace='/test')
@login_required
def join_user_room():
    room=current_user.slug
    join_room(room)
    emit('my response', {'data': username + ' has joined'}, room=room, broadcast=True)