Bom dia (Good Morning) I am implementing super to...
# general
f
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
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
Thank you for the insight
I'll look further and report to you later, for later users that come across this issue
r
perfect. thank you!
f
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
hmmm I see.
f
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
@User have a look at this thread. Same issue as you.
s
thx @User
should i apply this in apps?
r
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
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
Same error?
s
yeah
r
Can I see your code? The part that’s giving the error
s
sure
r
You want to call the get_all_cors function inside the ready function
At the end of the ready function
s
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
I’m really not sure what you mean.
can I see the error?
s
umm
okay
its not in the stack trace at all
its vs code that has the issue
first example
r
Well. Are you able to run the program?
s
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
You have put that inside the init call
s
the more i take it up the more i have to close
oh
r
Can you copy paste the code here so I can edit it
s
okay
words were too long sorry :/
r
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
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
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
Thank you @User
s
just a quick one
its suppose to tell me no supertoken core available to query
then i start setting up the core?
r
Not sure what you mean. What’s the value of your connection_uri now?
s
you mean whats written in my code?
r
Yes
s
"https://c75917c1a9f111ec8ccb73a204aeb225-eu-west-1.aws.supertokens.io:3568"
r
Right. So you have already setup the core
You are using our managed service
s
i do i become self hosted?
r
Do you mean how do you become self hosted?
s
i mean
i didnt intend to be under managed service
r
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
okay
ill do so
8 Views