diff --git a/app_users/models.py b/app_users/models.py index 3ba30e885..fafb8c233 100644 --- a/app_users/models.py +++ b/app_users/models.py @@ -150,6 +150,7 @@ def copy_from_firebase_user(self, user: auth.UserRecord) -> "AppUser": self.display_name = user.display_name or "" self.email = user.email self.phone_number = user.phone_number + provider_list = user.provider_data self.created_at = timezone.datetime.fromtimestamp( user.user_metadata.creation_timestamp / 1000 ) @@ -175,14 +176,15 @@ def copy_from_firebase_user(self, user: auth.UserRecord) -> "AppUser": self.is_anonymous = is_anonymous_now # get existing balance or set free credits + default_balance = settings.LOGIN_USER_FREE_CREDITS + if self.is_anonymous: + default_balance = settings.ANON_USER_FREE_CREDITS + elif provider_list[-1].provider_id == "password": + default_balance = settings.EMAIL_USER_FREE_CREDITS self.balance = db.get_doc_field( doc_ref=db.get_user_doc_ref(user.uid), field=db.USER_BALANCE_FIELD, - default=( - settings.ANON_USER_FREE_CREDITS - if self.is_anonymous - else settings.LOGIN_USER_FREE_CREDITS - ), + default=default_balance, ) return self diff --git a/daras_ai_v2/settings.py b/daras_ai_v2/settings.py index fe81fd829..5046ee5f5 100644 --- a/daras_ai_v2/settings.py +++ b/daras_ai_v2/settings.py @@ -243,6 +243,7 @@ SAFTY_CHECKER_BILLING_EMAIL = "support+mods@gooey.ai" CREDITS_TO_DEDUCT_PER_RUN = config("CREDITS_TO_DEDUCT_PER_RUN", 5, cast=int) +EMAIL_USER_FREE_CREDITS = config("EMAIL_USER_FREE_CREDITS", 0, cast=int) ANON_USER_FREE_CREDITS = config("ANON_USER_FREE_CREDITS", 25, cast=int) LOGIN_USER_FREE_CREDITS = config("LOGIN_USER_FREE_CREDITS", 1000, cast=int)