Thread
#general
    fsimoes

    fsimoes

    6 months ago
    Hello, question: Is there any way to write to django database after User Login? I assumed altering:
    from django.contrib.auth.models import User
    async def get_profile_info(self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
            user = something_that_gets_users(auth_code_response["access_token"])
            User.objects.create(username=user.id, email=user.personal.email) # Write to database
            return UserInfo(user_id=user.id,
                            email=UserInfoEmail(email=user.personal.email, email_verified=True))
    Problem: It raises
    AppRegistryNotReady("Apps aren't loaded yet.")
    Import
    from django.contrib.auth.models import User
    inside the function itself
    example:
    async def get_profile_info(self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]) -> UserInfo:
            user = something_that_gets_users(auth_code_response["access_token"])
    
            from django.contrib.auth.models import User # Import here
            User.objects.create(username=user.id, email=user.personal.email) # Write to database
    
            return UserInfo(user_id=user.id,
                            email=UserInfoEmail(email=user.personal.email, email_verified=True))
    r

    rp

    6 months ago
    Which recipe are you using?
    You don't want to do that in the
    get_profile_info
    function.
    (the above link assumes that you are using thirdpartyemailpassword)