Codespaces: How to create postgres user?

I tried to run this in Codespaces:

createuser -W $user

but after entering password, the follow errors appear:

createuser: error: could not connect to database template1: FATAL:  role "codespace" does not exist

I then tried:

psql -U postgres

but it errors:

psql: error: FATAL:  Peer authentication failed for user "postgres"

I also tried:

sudo -u postgres psql

and it asks for sudo password, which I don’t know.

You’ll need to adjust your pg_hba.conf to allow non-peer local authentication. I usually set local connections to trust for dev environments. You could also use something like md5 and supply a password.