Hi, I'm having an issue connecting a frontend reac...
# general
a
Hi, I'm having an issue connecting a frontend react app to a backend python api. When I run the python api I am getting this:
Copy code
File "/home/tobias/miniconda3/envs/memorizer/lib/python3.8/site-packages/supertokens_python/supertokens.py", line 115, in manage_cookies_post_response
    if session['remove_cookies']:
TypeError: 'NoneType' object is not subscriptable
The connectionuri/api keys are the same, and CORS seems to be working for everything. Could someone point me to what I'm doing wrong?
it happens on a post request. on a get request I get a 401 unauthorized reqponse
*now i get 401 on an post req as well
r
hey @User could you also show the code for how you have integrated supertokens? And the API code for where you get this error?
a
sure the request:
Copy code
app.route('/handleQuery', methods=['POST'])
@verify_session()
def handle_query():
    params = flask.request.get_json()
    if params is None:
        return "request not json"
    session_ = g.supertokens
    if session_ is not None:
        userid = session_.get_user_id()
        with open('test','w') as f:
            f.write(userid)
        userinfo = get_user_by_id(userid)

        email = userinfo.email
        mem =  Memorizer(MONGOIP, MONGOPORT, email)
        res = get_similar(params['query'],      mem
    else:
        res = "no user"
    return {'res': res}
Copy code
init(
    supertokens_config=SupertokensConfig(
        connection_uri=CONNECTIONURI,
        api_key=APIKEY
    ),
    app_info=InputAppInfo(
        app_name='Memorizer',
        api_domain=get_api_domain(),
        website_domain=get_website_domain()
    ),
    framework='flask',
    recipe_list=[
        session.init(),
        emailpassword.init()
    ],
    telemetry=False
)

import logging
logger = logging.getLogger('waitress')
logger.setLevel(logging.DEBUG)

app = flask.Flask(__name__)
app.make_default_options_response = make_default_options_response
Middleware(app)

CORS(
    app=app,
    supports_credentials=True,
    origins=["https://search.diva.so", "https://auth.diva.so", "https://console.diva.so", "http://localhost"],
    #allow_headers=['Content-Type'] + get_all_cors_headers()
)
the post request is coming from search.diva.so, the auth server is auth.diva.so
r
I think this may be a bug in the SDK. Can you please open an issue about this? Also, we are in the process of releasing a new version of the python SDK which fixes a bug of bugs (the release will happen tomorrow). That might fix this issue.
Yea, this is cause of a bug in the version in the python SDK that is being used by you. It's fixed in branch 0.5 of the repo, and we will be releasing it tomorrow most likely, so you will just need to upgrade to that, and the bug will go away 🙂
a
thanks! is there a way I can run the branch locally for now?
r
Yes. You can do
pip install git+https://github.com/supertokens/supertokens-python.git@0.5
a
sweet
please lmk if the error still persists 🙂
a
also is the issue with the sdk getting the NoneType error or the 401? I switched around some code so I don't know if I broke something on my end to get the 401
r
yea. that's cause of a bug in the SDK
but it shouldn't happen with the new version
a
ok cool, thanks for the help
r
in case the error goes away, please let me know!
Would help 🙂
a
I'm still getting the same issue
r
Oh. Hmm. At the same line?
As in line 115 still? Or a different lint number?
a
It doesn't throw an error anymore, just returns a 401
r
Ah I see. That’s probably cause you don’t have the session cookies set? Can I see the request headers?
a
Copy code
Request URL: https://mk1.diva.so:4242/handleQuery
Request Method: POST
Status Code: 401 UNAUTHORIZED
Remote Address: 68.194.59.69:4242
Referrer Policy: strict-origin-when-cross-origin

Response:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://search.diva.so
Connection: keep-alive
Content-Length: 26
Content-Type: application/json
Content-Type: application/json; charset=utf-8
Date: Mon, 21 Feb 2022 18:01:53 GMT
Server: gunicorn
Vary: Origin

Request: 
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 12
Content-Type: application/json
Host: mk1.diva.so:4242
Origin: https://search.diva.so
Referer: https://search.diva.so/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
Sec-GPC: 1
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Mobile Safari/537.36
r
The cookies are missing. How are you querying the server? From the frontend? Does that use our frontend SDK?
a
post is done here:
Copy code
let response = await axios.post(memorizerURL,
            {query: updatingQuery},
            {headers: { 
               "Content-Type": "application/json",
               "Access-Control-Allow-Origin": "*",
            }}
        );
r
What’s the value for website domain that you have set?
Sorry I mean api domain. What’s the value for that that’s set?
a
auth.diva.so
r
You need to set the api domain to be = mk1.diva.so:4242
Since you are querying that
a
ah ok, what do I set it to be if it talks to multiple subdomains?
r
a
ok thanks
so would I still be setting api domain to be mk1?
and would cookie_domain be set for all backend servies too?
ie auth as well
r
No. You would set the apiDomain to auth.diva.so:4242 since I assume that’s where you want all the auth related APIs to be
Yes. It would be set for all backend services.
a
got it to work, thanks for the help!
5 Views