1

I'm building a user signup feature into an application using Node.JS, PostgreSQL for database and 'pg' for ORM.

The user provides their email, password, phone, country and the data is stored into the Postgresql database along with other metadata.

The code works fine when I test it locally on my computer.

However, when I try using it in production, I get an error that looks like below if the user submits the signup data.


{"length":102,"name":"error","severity":"ERROR","code":"42501","file":"sequence.c","line":"463","routine":"nextval_internal"}

I can't figure out if this is a postgresQL database error, or a Node.JS error.

The error files (stderr) in my production 'file manager' do not record any errors.

The Node.JS database query looks like below;


db.query('INSERT INTO traveler (name, email, phone, password, joined, uid, status, verification, photo, forgot, type, country, platform) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
                        [name, email, phone, encryptedPWD, date, uid, status, verification, imgBio, forgot, type, country, platform]

Could you please help me spot the problem?

Thanks in advance!

The Posgresql 'traveler' database table schema looks like below.


CREATE TABLE IF NOT EXISTS traveler (
  id SERIAL PRIMARY KEY NOT NULL,
  phone varchar(20) NOT NULL,
  email varchar(255) NOT NULL,
  name varchar(255) NOT NULL,
  joined varchar(255) NOT NULL,
  uid varchar(255) NOT NULL,
  verification varchar(10) NOT NULL,
  status varchar(10) NOT NULL,
  photo varchar(255) NULL,
  password varchar(255) NOT NULL,
  type varchar(255) NULL,
  country varchar(255) NULL,
  forgot varchar(255) NULL,
  platform varchar(255) NULL,
);

1
  • "I can't figure out if this is a postgresQL database error" - it is. Commented Oct 3, 2022 at 19:13

1 Answer 1

3

The error code 42501 corresponds to Insufficient Privilege from PostgreSQL. From the error, it seems the user is missing USAGE and SELECT permission on the sequence table of the table in which you're trying to do insert.

You can fix this by giving the right permission to the user:

GRANT USAGE, SELECT ON SEQUENCE <table_id_seq> TO user;

Or you can choose to grant the USAGE permission on all sequence tables in your current schema.

GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO user;

You can read more about granting permissions here.

Sign up to request clarification or add additional context in comments.

2 Comments

More likely a missing usage permission on the sequence for the id sequence?
Thanks for pointing that out. I've modified accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.