Hey! I'm trying to implement passwordless in an app built in Python/Flask, and am having trouble gra...
c
Hey! I'm trying to implement passwordless in an app built in Python/Flask, and am having trouble grasping some of the implementation instructions here. Hoping to get some help with a couple questions: 1. The backend docs call for both "api_domain" and "website_domain". what is the difference between these two? I thought possibly one needed to be the postgres uri, but then I noticed a separate "connection_uri" variable in
SupertokensConfig
.. 2. Does SuperTokens need to be initialized twice for Flask apps? I.e., once in a JS script for front end and again in the main
app.py
file? Or just once in
app.py
?
r
Hey @callstack1
1. Since your frontend and APIs are served on the same server, the value of api_domain and website_domain is the same and should point to your flask server’s address
2. Yes. Both need to be initialised. One is for frontend and one for backend.
c
Okay, got it. Then I'm assuming that
connection_uri
needs to be the uri established when setting up the Postgre docker container? Which leads to my next question - our app uses Postgre when running on our production server, but local test environments use SQLite. Is it possible to use a SQLite db as the supertokens core instance for local testing purposes? I tried making a new db using the schema listed in the docs and passing it to connection_uri, but got
SERVER ERROR: Failed to load user list. Please refresh to try again.
after I entered the API key on
<my_url>/auth/dashboard
r
Connection uri is the location of the supertokens core.
They supertokens core connects to your db.
The backend SDK doesn’t connect to the db directly.
c
Ah, got it - makes sense. So if we are hosting supertokens core at
tokens.<oururl>
, then this should be the value of connection uri? I changed to this url, but now am getting this error when loading the dashboard:
Although, now that I think about it.. our supertokens core is running in a docker container hosted at
tokens.<oururl>.com
, but our dev workflow requires the app to be run locally for testing purposes.. Could this be the source of the issue, or is this likely due to incorrect setup somewhere?
Hey @rp_st , wanted to update & add some additional context. I am now running both the app and SuperTokens in their separate Docker containers, but am still getting the "No SuperTokens core available" error. Here is my front-end init:
Copy code
<script>
  supertokens.init({
  appInfo: {
    apiDomain: "https://staging.<my_url>.com",
      apiBasePath: "/auth",
      appName: "..."
    },
    recipeList: [
      supertokensSession.init(),
      supertokensPasswordless.init(),
    ],
  });
</script>
And my backend init:
Copy code
init(
    app_info=InputAppInfo(
        app_name="...",
        api_domain="https://staging.<my_url>.com",
        website_domain="https://staging.<my_url>.com",
        api_base_path="/auth",
        website_base_path="/auth"
    ),
    supertokens_config=SupertokensConfig(
        connection_uri="https://tokens.<my_url>.com",
        api_key="<MY API KEY>"
    ),
    framework='flask',
    recipe_list=[
        dashboard.init(api_key="<MY API KEY>"),
        session.init(),
        passwordless.init(
            flow_type="MAGIC_LINK",
            contact_config=ContactEmailOnlyConfig()
        )
    ]
)

Middleware(app)
CORS(
    app=app,
    origins=[
        "https://staging.<my_url>.com"
    ],
    supports_credentials=True,
    allow_headers=["Content-Type"] + get_all_cors_headers(),
)
https://tokens.<my_url>.com
is the hosted url that should be connected to our supertokens postgres (which seems to be up and running)
r
if you visit
https://tokens.<my_url>.com
, on the browser, do you get a "Hello" message back?
c
Hey @rp_st, yes I do get the "Hello" message
r
Right. So the core is working fine.
Might be some firewall issue in the python server,
?
c
I suppose it's possible. So the backend init looks to be correct, then?
r
Yea. Seems like it.
c
May have found the issue - I changed
connection_uri
to
http://supertokens:3567
and now am getting this screen when I visit
\auth\dashboard
r
Yea. That’s working now.
c
Awesome. Thanks so much for the help!
4 Views