Alex
Alex

Reputation: 335

Flask 405 when Pusher JS calls the auth route

I have Pusher Presence channels working fine on my local machine, with a Flask back end.

When I go live, however, it falls over, with Flask returning a 405. Locally there is a preflight call being made - live, it simply makes the POST request.

The Flask route is I believe correctly configured, and indeed serves POST requests happily on localhost:

@app.route('/pusher/auth', methods=['POST'])
def pusher_authentication():
    try:
        auth_response = dauth.check_auth()
    except AuthError:
        response = jsonify({'error': 'Not Authorised'})
        return response, 401
        
    auth = pusher_client.authenticate(
        channel=request.form['channel_name'],
        socket_id=request.form['socket_id'],
        custom_data={
            u'user_id': auth_response['sub'],
            u'user_info': {
                u'first_name':
                auth_response['https://platform.demeterdata.ag/user_metadata']['first_name'],
                u'last_name':
                auth_response['https://platform.demeterdata.ag/user_metadata']['last_name']
            }
        }
    )

My connection to Pusher looks like this:

      const pusher = new Pusher(import.meta.env.VITE_PUSHER_KEY, {
        cluster: import.meta.env.VITE_PUSHER_CLUSTER,
        authEndpoint: import.meta.env.VITE_PUSHER_AUTH_URL,
        auth: {
          headers: {
            'Authorization': `Bearer ${accessToken}`,
          },
        },
      });

All bright ideas welcome :)

Upvotes: 0

Views: 15

Answers (0)

Related Questions