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)