So I am using `FastAPI` and I would believe that t...
# support-questions-legacy
b
So I am using
FastAPI
and I would believe that the
Middleware
will add the
/auth
endpoints (set website_base_path) to the fastapi application, but it does not. I dont see any errors though. I tried the example from github, but no success ( https://github.com/supertokens/supertokens-python/blob/master/examples/with-fastapi/with-thirdpartyemailpassword/main.py )
Copy code
INFO:     127.0.0.1:39268 - "POST /auth/signinup/code HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:39270 - "POST /signinup/code HTTP/1.1" 404 Not Found
Anything known that could be the cause for the endpoints not being added?
r
hey! Can you please enable backend debug logs and show me the output of it when you call this API?
you can see the troubleshooting section on how to enable backend debug logs
b
starting log
ohhh I see
Copy code
api_1              | com.supertokens {"t": "2022-09-24T04:25:58.816Z", "sdkVer": "0.11.0", "message": "middleware: Not handling because request path did not start with config path. Request path: //auth/signinup/code", "file": "supertokens.py:543"}
api_1              | 
api_1              | DEBUG:     {"t": "2022-09-24T04:25:58.816Z", "sdkVer": "0.11.0", "message": "middleware: Not handling because request path did not start with config path. Request path: //auth/signinup/code", "file": "supertokens.py:543"} (line:543)
api_1              | INFO:     172.20.0.1:54494 - "POST /auth/signinup/code HTTP/1.1" 404 Not Found
r
So the value of api_domain should be = to the python backend's domain.
Huh.. it says the request path is
//auth/signinup/code
- did you add a double
//
at the start of the request?
b
nope, just
Copy code
# curl -X POST http://127.0.0.1:8000/auth/signinup/code
let me remove the leading
/
in the config and try again
r
the value of api_domain should be
http://127.0.0.1:8000
b
yeah changed that as well, so now
Copy code
api_domain="http://localhost:8000",
    website_domain="http://localhost:8000",
    api_base_path="auth",
    website_base_path="auth"
but same error
r
that's strange.. why is it considering path as
//auth/signinup/code
when it's
/auth/signinup/code
b
look at this, its still
/auth
at the startup
Copy code
api_1              | DEBUG:     {"t": "2022-09-24T04:29:15.480Z", "sdkVer": "0.11.0", "message": "app_info: {
api_1              |     "api_base_path": "/auth",
api_1              |     "api_domain": "http://localhost:8000",
api_1              |     "api_gateway_path": "",
api_1              |     "app_name": "Patchwork",
api_1              |     "framework": "fastapi",
api_1              |     "mode": "asgi",
api_1              |     "website_base_path": "/auth",
api_1              |     "website_domain": "http://localhost:8000"
api_1              | }", "file": "supertokens.py:210"} (line:210)
r
Can you please open an issue about this on our github please?
b
even so the
api_base_path
does have no
/
r
right. We will check it out - if you could open an issue on our github, it would be most helpful 🙂
b
sure will do
even if I remove
Copy code
api_base_path="auth",
    website_base_path="auth"
it still show up in the debug as above for
/auth
r
yea.. thats expected
whats not expected is that it reads the request path as
//auth/signinup/code
even running the example app we have doesn't work?
@KShivendu can help here perhaps
b
different for the demo app 🤔
Copy code
com.supertokens {"t": "2022-09-24T04:46:20.518Z", "sdkVer": "0.11.0", "message": "middleware: Started", "file": "supertokens.py:536"}

com.supertokens {"t": "2022-09-24T04:46:20.519Z", "sdkVer": "0.11.0", "message": "middleware: requestRID is: None", "file": "supertokens.py:549"}

com.supertokens {"t": "2022-09-24T04:46:20.519Z", "sdkVer": "0.11.0", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:573"}

com.supertokens {"t": "2022-09-24T04:46:20.520Z", "sdkVer": "0.11.0", "message": "middleware: Checking recipe ID for match: emailverification", "file": "supertokens.py:573"}

com.supertokens {"t": "2022-09-24T04:46:20.521Z", "sdkVer": "0.11.0", "message": "middleware: Checking recipe ID for match: thirdpartyemailpassword", "file": "supertokens.py:573"}

com.supertokens {"t": "2022-09-24T04:46:20.523Z", "sdkVer": "0.11.0", "message": "middleware: Not handling because no recipe matched", "file": "supertokens.py:586"}

INFO:     127.0.0.1:39292 - "POST /auth/signinup/code HTTP/1.1" 404 Not Found
r
the recipe in the demo app uses thirdpartyemailpassword, but the path you are querying for is in the passwordless recipe
k
Hey @bert2002 I just tried replicating the setup but it's working fine for me. can you please share your init() function call 😄 (pls. replace credentials with placeholders)
b
in the demo app and I would say thats expected
Copy code
# curl -X POST http://127.0.0.1:3001/auth/signin
{"message":"Are you sending too many / too few formFields?"}
and result
Copy code
INFO:     127.0.0.1:39302 - "POST /auth/signin HTTP/1.1" 400 Bad Request
looks like this
Copy code
init(
  supertokens_config=SupertokensConfig(
    connection_uri="http://supertokens:3567",
    api_key=os.environ.get("SUPERTOKENS_API_KEY")
  ),
  app_info=InputAppInfo(
    app_name="Patchwork",
    api_domain="http://localhost:8000",
    website_domain="http://localhost:8000",
    api_base_path="/auth",
    website_base_path="/auth"
  ),
  framework="fastapi",
  recipe_list=[
    session.init(),
    emailverification.init("REQUIRED"),
    thirdpartypasswordless.init(
      flow_type="USER_INPUT_CODE_AND_MAGIC_LINK",
      contact_config=ContactEmailOnlyConfig(),
      #email_delivery=EmailDeliveryConfig(
      #  service=thirdpartypasswordless.SMTPService(
      #    smtp_settings=smtp_settings
      #  )
      #)
    ),
    thirdpartyemailpassword.init(
      providers=[
        Google(
          is_default=True,
          client_id=os.environ.get("GOOGLE_CLIENT_ID"),
          client_secret=os.environ.get("GOOGLE_CLIENT_SECRET"),
        )
      ]
    ),
  ],
  telemetry=False,
  mode='asgi'
)
ah its fastapi itelf
Copy code
app = FastAPI(
  root_path=os.environ.get('FASTAPI_ROOT_PATH'),
)
and
root_path
is set to
/
k
hmm.
so is it working now?
b
so if I dont set the
root_path
it works, e.g.
Copy code
app = FastAPI()
and the supertoken config like this:
Copy code
app_info=InputAppInfo(
    app_name="Patchwork",
    api_domain="http://localhost:8000",
    website_domain="http://localhost:8000",
    api_base_path="/auth",
    website_base_path="/auth"
  ),
Then I can reach eh api e.g.
Copy code
# curl http://localhost:8000/auth/signin -X POST
{"message":"Are you sending too many / too few formFields?"}
k
cool.
let me know if you have any other questions 😄
b
but if I set the
root_path
it will not work anymore e.g.
Copy code
app = FastAPI(
  root_path="/api",
)
and the config (doesnt matter actually, always the same)
Copy code
app_info=InputAppInfo(
    app_name="Patchwork",
    api_domain="http://localhost:8000",
    website_domain="http://localhost:8000",
    api_base_path="/auth",
    website_base_path="/auth"
  ),
then we get:
Copy code
# curl http://localhost:8000/api/auth/signin -X POST
{"detail":"Not Found"}
and
Copy code
api_1              | DEBUG:     {"t": "2022-09-24T05:10:45.061Z", "sdkVer": "0.11.0", "message": "middleware: Not handling because request path did not start with config path. Request path: /api/api/auth/signin", "file": "supertokens.py:543"} (line:543)
so seems to me that when
root_path
of the FastAPI() is set, it duplicates it
will open an issue for that
k
thanks!
k
Thanks! @bert2002
23 Views