fsimoes

    fsimoes

    6 months ago
    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

    6 months ago
    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
    fsimoes

    fsimoes

    6 months ago
    Thank you for the insight
    I'll look further and report to you later, for later users that come across this issue
    r

    rp

    6 months ago
    perfect. thank you!
    fsimoes

    fsimoes

    6 months ago
    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

    6 months ago
    hmmm I see.
    fsimoes

    fsimoes

    6 months ago
    Final spauth/apps.py 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

    5 months ago
    @User have a look at this thread. Same issue as you.
    shorthair_[]

    shorthair_[]

    5 months ago
    thx @User
    should i apply this in apps?
    r

    rp

    5 months ago
    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
    shorthair_[]

    shorthair_[]

    5 months ago
    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

    5 months ago
    Same error?
    shorthair_[]

    shorthair_[]

    5 months ago
    yeah
    r

    rp

    5 months ago
    Can I see your code? The part that’s giving the error
    shorthair_[]

    shorthair_[]

    5 months ago
    sure
    message has been deleted
    message has been deleted
    r

    rp

    5 months ago
    You want to call the get_all_cors function inside the ready function
    At the end of the ready function
    shorthair_[]

    shorthair_[]

    5 months ago
    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

    5 months ago
    I’m really not sure what you mean.
    can I see the error?
    shorthair_[]

    shorthair_[]

    5 months ago
    umm
    okay
    its not in the stack trace at all
    its vs code that has the issue
    first example
    r

    rp

    5 months ago
    Well. Are you able to run the program?
    shorthair_[]

    shorthair_[]

    5 months ago
    no i cant 😕
    first example
    i put the function just under everything
    like this
    message has been deleted
    message has been deleted
    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

    5 months ago
    You have put that inside the init call
    shorthair_[]

    shorthair_[]

    5 months ago
    the more i take it up the more i have to close
    oh
    r

    rp

    5 months ago
    Can you copy paste the code here so I can edit it
    shorthair_[]

    shorthair_[]

    5 months ago
    okay
    message has been deleted
    words were too long sorry 😕
    r

    rp

    5 months ago
    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
    fsimoes

    fsimoes

    5 months ago
    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.
    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()
    message has been deleted
    This is my suggestion
    then, on your settings.py:
    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
    shorthair_[]

    shorthair_[]

    5 months ago
    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

    5 months ago
    Thank you @User
    shorthair_[]

    shorthair_[]

    5 months ago
    just a quick one
    its suppose to tell me no supertoken core available to query
    then i start setting up the core?
    r

    rp

    5 months ago
    Not sure what you mean. What’s the value of your connection_uri now?
    shorthair_[]

    shorthair_[]

    5 months ago
    you mean whats written in my code?
    r

    rp

    5 months ago
    Yes
    shorthair_[]

    shorthair_[]

    5 months ago
    "https://c75917c1a9f111ec8ccb73a204aeb225-eu-west-1.aws.supertokens.io:3568"
    r

    rp

    5 months ago
    Right. So you have already setup the core
    You are using our managed service
    shorthair_[]

    shorthair_[]

    5 months ago
    i do i become self hosted?
    r

    rp

    5 months ago
    Do you mean how do you become self hosted?
    shorthair_[]

    shorthair_[]

    5 months ago
    i mean
    i didnt intend to be under managed service
    r

    rp

    5 months ago
    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
    shorthair_[]

    shorthair_[]

    5 months ago
    okay
    ill do so