Is using Cognito Id as a primary key in your own database a good idea?

Viewed 26

I am currently using Cognito and Django together. I also have a rds postgres instance as my db.

I am curious what are the pros and cons of using CognitoId as my User's primary key versus having unique uuid4 primary key for my user and a cognito_id field.

class User(AbstractUser):
    user_id = models.UUIDField(primary_key=True, default=uuid4) 
    cognito_id = models.UUIDField(default=uuid.uuid4, editable=False)

OR

class User(AbstractUser):
    cognito_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

Are there any reasons the second version that uses cognitoID would run into issues?

1 Answers

For your use case there is no issue. You can use sub Id as the primary key in your database, it is globally unique. Only if you plan to use this database to restore users, you won't be able to restore the sub id. It will generate a new one. But I don't think that is part of your use case anyway.

Related