0

I am trying to create an app which a web3 user can use their wallet to sign in BUT I want the superuser to still use a username/password. (my future plan is to create a custom backend to do the web3 auth flow)

I was close with this as I was able to create a first admin that could use the username/password but realized it was failing on the next createsuperuser with this:

django.db.utils.IntegrityError: UNIQUE constraint failed: users_web3user.public_address

So I tried for now just adding a random integer to satisfy that just to see if it would work but the same issue constantly shows up.

Would this be the proper way to go about this and to seperate my users from my superusers? Also, my debugger is never called even though I have set in my settings.py where user is my app: AUTH_USER_MODEL = 'users.Web3User'

models.py: class Web3UserManager(BaseUserManager): def create_user(self, public_address): if not public_address: raise ValueError('Users must have a public_address')

        user = self.model(
            public_address=public_address,
            nonce=secrets.token_urlsafe(32)
        )

        user.save(using=self._db)
        return user

    def create_superuser(self, username, password=None):
        import ipdb; ipdb.sset_trace()
        public_address=secrets.randbelow(299)
        print(public_address)
        user = self.create_user(
            username=username,
            password=password,
            public_address=public_address
        )
        user.is_admin = True
        user.save(using=self._db)
        return user



class Web3User(AbstractUser):
    public_address = models.CharField(max_length=64, unique=True)
    nonce = models.CharField(max_length=64)
Kyle Calica-St
  • 2,629
  • 4
  • 26
  • 56
  • 1
    Did you realise that your debugger is never hit? Set `objects = Web3UserManager()` in `Web3User` and you should be able to figure out the rest. – aaron Oct 24 '21 at 12:31
  • 1
    I’m voting to close this question because while similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. – aaron Nov 07 '21 at 13:42
  • sure! I figured it out too btw! – Kyle Calica-St Nov 09 '21 at 11:44

1 Answers1

-1
django_custom_user==0.7
AUTH_USER_MODEL = 'user.UserModel' -> settings.py

class UserModel(AbstractEmailUser, BaseModelFields):
   pass

Use package instead of making some cool logic.

Marin
  • 1,098
  • 14
  • 33