Hello, I am getting a error after logout. I am usi...
# support-questions-legacy
l
Hello, I am getting a error after logout. I am using the python sdk with fastapi. This is the error message:
Copy code
...
File "/home/.../app/venv/lib/python3.9/site-packages/supertokens_python/recipe/session/api/implementation.py", line 46, in signout_post
    session = await api_options.recipe_implementation.get_session(
TypeError: get_session() got an unexpected keyword argument 'anti_csrf_check'
r
Hey! Can you please open an issue about this on our GitHub?
Hey! Can you please open an issue about this on our GitHub? @Luca
@KShivendu can help out
k
Hey @Luca. Have you overridden something? Could you please share your SuperTokens init(...) function call?
l
Hi @KShivendu , Here is the code of my `init`: I am overriding some things:
Copy code
python
    init(
        app_info=InputAppInfo(
            app_name="Test",
            api_domain=API_HOST,
            website_domain="localhost:3000",
            api_base_path="/auth",
            website_base_path="/auth"
        ),
        supertokens_config=SupertokensConfig(
            connection_uri=SUPERTOKENS_CONNECTION_URI,
            api_key=SUPERTOKENS_API_KEY
        ),
        framework='fastapi',
        recipe_list=[
            session.init(
                jwt=session.JWTConfig(
                    enable=True
                ),
                override=session.InputOverrideConfig(
                    functions=override_session_functions
                )
            ),
            thirdpartyemailpassword.init(
                sign_up_feature=thirdpartyemailpassword.InputSignUpFeature(
                    form_fields=[InputFormField(id='name')]
                ),
                providers=[
                    Google(
                        client_id='...',
                        client_secret='...'
                    ),
                    Apple(
                        client_id="...",
                        client_key_id="...",
                        client_private_key="...",
                        client_team_id="..."
                    )
                ],
                email_delivery=EmailDeliveryConfig(
                    override=email_delivery_override
                ),
                override=thirdpartyemailpassword.InputOverrideConfig(
                    apis=override_thirdparty_email_password_apis
                )
            )
        ],
        mode='wsgi'
    )
And here are my session overrides:
Copy code
python
def _update_headers_in_request(rq: BaseRequest):
    rq: Request = rq.request
    new_headers = rq.headers.mutablecopy()
    if st_cookie := rq.headers.get(SUPERTOKENS_HEADER):
        current = new_headers.get('cookie') or ''
        new_headers['cookie'] = f'f{current}; {st_cookie}'
    rq._headers = new_headers
    rq.scope.update(headers=rq.headers.raw)


def override_session_functions(oi: RecipeInterface):
    original_create_new_session = oi.create_new_session
    original_refresh_session = oi.refresh_session
    original_get_session = oi.get_session

    async def create_new_session(request, user_id, access_token_payload, session_data, user_context):
        _update_headers_in_request(request)
        session = await original_create_new_session(request, user_id, access_token_payload, session_data, user_context)
        return session

    async def refresh_session(request, user_context):
        _update_headers_in_request(request)
        session = await original_refresh_session(request, user_context)
        return session

    async def get_session(request, anti_csrf, session_required, user_context):
        _update_headers_in_request(request)
        session = await original_get_session(request, anti_csrf, session_required, user_context)
        return session

    oi.create_new_session = create_new_session
    oi.refresh_session = refresh_session
    oi.get_session = get_session

    return oi
k
Hey @Luca, can you please try renaming
anti_csrf
to
anti_csrf_check
in your override like this:
Copy code
python
async def get_session(request, anti_csrf_check, session_required, user_context):
    _update_headers_in_request(request)
    session = await original_get_session(request, anti_csrf_check, session_required, user_context)
    return session
If you're curious about the reason: The error comes from `signout_post()`which uses
session = await api_options.recipe_implementation.get_session(...)
If you see its source code, we pass
anti_csrf_check=None
but since the override has changed the arg name to
anti_csrf
, we face an error. Let me know if you face any problem 😄
l
@KShivendu Now it works, thanks.
r
thanks @KShivendu