https://supertokens.com/ logo
#general
Title
# general
f

fsimoes

03/26/2022, 10:42 AM
Bom dia (Good Morning) I am implementing super tokens on django (backend), using thirdparty (only) recipe. I would like your opinions for best practices on how to initialize it. Currently I have a module and using the module config, I'm calling the start method where I have the init function. (I'll attach some screenshots) Still says that it is not initialized
Bom dia (Good Morning) I am implementing super tokens on django (backend), using thirdparty (only) recipe. I would like your opinions for best practices on how to initialize it. Currently I have a module and using the module config, I'm calling the start method where I have the init function. (I'll attach some screenshots) Still says that it is not initialized
:)
spauth/apps.py
controller/settings.py
supertokens_python.exceptions.GeneralError: Initialisation not done. Did you forget to call the SuperTokens.init function?
I'm accepting suggestions on how to make it work, the way it was planned to hehe
r

rp

03/26/2022, 11:11 AM
hey @User
So this is happening cause the corsheader function (I assume that calls
supertokens.get_all_cors_header
) is running before the
SuperTokensConfig
function
If you can make sure that the init is done before, then this error should go away
f

fsimoes

03/26/2022, 11:15 AM
Thank you for the insight
I'll look further and report to you later, for later users that come across this issue
r

rp

03/26/2022, 11:16 AM
perfect. thank you!
f

fsimoes

03/26/2022, 2:20 PM
Solution: ```from django.conf import settings settings.CORS_ALLOW_HEADERS += get_all_cors_headers()```After init This shouldn't be done as stated in the docs: https://docs.djangoproject.com/en/4.0/topics/settings/#altering-settings-at-runtime Anyways, it's the only way that I've found to make it work
r

rp

03/26/2022, 2:22 PM
hmmm I see.
f

fsimoes

03/26/2022, 2:22 PM
Final spauth/apps.py code:
Copy code
class SuperTokensConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'spauth'

    def ready(self):
        init(
            app_info=InputAppInfo(
                app_name="Example",
                api_domain="Example",
                website_domain="Example",
                api_base_path="/api/auth/",
                website_base_path="/"
            ),
            supertokens_config=SupertokensConfig(
                connection_uri="Example"
            ),
            framework='django',
            recipe_list=[
                session.init(),
                thirdparty.init(
                    sign_in_and_up_feature=thirdparty.SignInAndUpFeature(providers=[Example()])
                )
            ],
            mode='wsgi'  # wsgi/asgi
        )
        settings.CORS_ALLOW_HEADERS += get_all_cors_headers()
r

rp

03/27/2022, 8:27 PM
@User have a look at this thread. Same issue as you.
s

shorthair_[]

03/27/2022, 8:29 PM
thx @User
should i apply this in apps?
r

rp

03/27/2022, 8:44 PM
I’m not sure. But the point is that you should call the get_all_cors_header() function only after calling the supertokens.init function
s

shorthair_[]

03/27/2022, 8:45 PM
thanks for the explanation
ill give it a try
hey @User
i tried doing what you adviced and even asked fsimoes for some help but im still having some issues
r

rp

03/28/2022, 4:43 AM
Same error?
s

shorthair_[]

03/28/2022, 4:44 AM
yeah
r

rp

03/28/2022, 4:44 AM
Can I see your code? The part that’s giving the error
s

shorthair_[]

03/28/2022, 4:45 AM
sure
r

rp

03/28/2022, 4:47 AM
You want to call the get_all_cors function inside the ready function
At the end of the ready function
s

shorthair_[]

03/28/2022, 4:48 AM
lemme adjust rq.....
the function call isnt being recognised under the ready function
and i just get prompts to close functions and list so the get all cors headers part wouldnt be inside
r

rp

03/28/2022, 5:38 AM
I’m really not sure what you mean.
can I see the error?
s

shorthair_[]

03/28/2022, 5:39 AM
umm
okay
its not in the stack trace at all
its vs code that has the issue
first example
r

rp

03/28/2022, 5:40 AM
Well. Are you able to run the program?
s

shorthair_[]

03/28/2022, 5:41 AM
no i cant :/
first example
i put the function just under everything
like this
the line where the function is appears to be inactive and the init function wants to be closed outside the get all cors header function
r

rp

03/28/2022, 5:44 AM
You have put that inside the init call
s

shorthair_[]

03/28/2022, 5:44 AM
the more i take it up the more i have to close
oh
r

rp

03/28/2022, 5:44 AM
Can you copy paste the code here so I can edit it
s

shorthair_[]

03/28/2022, 5:44 AM
okay
words were too long sorry :/
r

rp

03/28/2022, 5:50 AM
Copy code
from django.apps import AppConfig
from django.conf import settings
from supertokens_python import (InputAppInfo, SupertokensConfig,
                                get_all_cors_headers, init)
from supertokens_python.recipe import session, thirdpartyemailpassword
from supertokens_python.recipe.thirdpartyemailpassword import (Apple, Github,
                                                               Google)


class ExpertsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'clients'

    def ready(self):
        init(
            app_info=InputAppInfo(
                app_name="patriot",
                api_domain="http://127.0.0.1:8000",
                website_domain="http://127.0.0.1:19000",
                api_base_path="/auth",
                website_base_path="/screens/signin"
            ),
            supertokens_config=SupertokensConfig(
                connection_uri="https://c75917c1a9f111ec8ccb73a204aeb225-eu-west-1.aws.supertokens.io:3568",
                api_key="4Pwu0ulPGO3LUjYvWvYH0Uxfr-tAmb"
            ),
            framework='django',
            recipe_list=[
                session.init(),
                thirdpartyemailpassword.init(
                     providers=[
                        Google(
                            client_id='1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com',
                            client_secret='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'
                        
                        ), Github(
                            client_id='467101b197249757c71f',
                            client_secret='e97051221f4b6426e8fe8d51486396703012f5bd'
                        ),
                        Apple(
                            client_id="4398792-io.supertokens.example.service",
                            client_key_id="7M48Y4RYDL",
                            client_private_key="-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----",
                            client_team_id="YWQCXGJRJL"
                        )
                     ]
                )
            ]
        )
        settings.CORS_ALLOW_HEADERS += get_all_cors_headers()
        
mode='asgi' # use wsgi if you are running django server in sync mode
f

fsimoes

03/28/2022, 7:16 AM
I'm a little late to the party hehe I noticed something
What I've written here,
settings.CORS_ALLOW_HEADERS += get_all_cors_headers()
comes after the init function is closed
aka.
Copy code
class SuperTokensConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'spauth'

    def ready(self):
        init(STUFF)
        settings.CORS_ALLOW_HEADERS += get_all_cors_headers()
This is my suggestion
then, on your `settings.py`:
Copy code
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'supertokens_python',
    '(folder).apps.SuperTokensConfig',
    'corsheaders'
]
And you should be up and running
s

shorthair_[]

03/28/2022, 8:20 AM
thanks so much guys ill give it a try
ill give it a go after class
this worked
thank you guys so much for your help and engagement
both of you were right
r

rp

03/28/2022, 5:53 PM
Thank you @User
s

shorthair_[]

03/28/2022, 6:09 PM
just a quick one
its suppose to tell me no supertoken core available to query
then i start setting up the core?
r

rp

03/28/2022, 6:12 PM
Not sure what you mean. What’s the value of your connection_uri now?
s

shorthair_[]

03/28/2022, 6:15 PM
you mean whats written in my code?
r

rp

03/28/2022, 6:16 PM
Yes
s

shorthair_[]

03/28/2022, 6:16 PM
"https://c75917c1a9f111ec8ccb73a204aeb225-eu-west-1.aws.supertokens.io:3568"
r

rp

03/28/2022, 6:16 PM
Right. So you have already setup the core
You are using our managed service
s

shorthair_[]

03/28/2022, 6:17 PM
i do i become self hosted?
r

rp

03/28/2022, 6:17 PM
Do you mean how do you become self hosted?
s

shorthair_[]

03/28/2022, 6:18 PM
i mean
i didnt intend to be under managed service
r

rp

03/28/2022, 6:19 PM
So you can setup your own core and change the connection uri
You can search our docs for self hosted core and see the steps there
s

shorthair_[]

03/28/2022, 6:19 PM
okay
ill do so
8 Views