score:0
You can use the function version with automatic generation of salt, just passing the saltRounds
:
const express = require("express");
const router = require("express").Router();
const bcrypt = require("bcrypt");
const pool = require("../../../db");
router.post("/register", async (req, res) => {
try {
const { email, password, name1, name2 } = req.body;
const user = await pool.query("SELECT * FROM userr WHERE email = $1", [email]);
if (user.rows.length !== 0) {
return res.status(401).send("user already exists"); // this works
}
const bcryptPassword = await bcrypt.hash(password, 10);
const newUser = await pool.query(
"INSERT INTO userr (lastName, firstName, email, passwrd) VALUES ($1, $2, $3, $4) RETURNING *",
[name1, name2, email, bcryptPassword]
);
res.json(newUser.rows[0]);
} catch (err) {
console.error(err.message);
res.status(500).send("server error");
}
});
module.exports = router;
If you are concerned about the performance of your application, you should not use .hashSync
because a synchronous operation will block the thread; instead, it is better to use .hash
along with await
.
More questions
- Error: data and salt arguments required (node js, bcrypt)
- Schema and data migrations for node js
- incorrect checksum in control file error for postgres 9.1.3 data created in osx-Lion and accessed in osx-snow-leopard
- bcrypt and postgresql. What data type should be used?
- Bcrypt Invalid Salt and Postgresql
- Bcrypt salt treating byte object as string and wont hash password
- Using ActiveRecord and Rails to insert Data into postgresql database get this error: RuntimeError: ERROR C22003 Minteger o
- Haskell and postgresql - build error "The program pg_config is required but it could not be found."
- Error retrieving data from DB using typeorm and type-graphql
- Heroku/Postgres "ClientAuthentication" Error with Node and node-postgres
- How to update or insert data with WITH subquery? and avoid `PG::UndefinedTable: ERROR: missing FROM-clause entry for table` error
- TypeError: Error while fetching data from PostgresSQL not all arguments converted during string formatting
- unable to connect to database from node script and there is no error thrown
- Error in designing a RESTful API With Node and Postgres
- Encoding error when reading data from one DB and inserting to another with PHP
- Field required a bean of type ... that could not be found - Error when using Springboot and Postgres
- unquoted newline found in data error and date/time field value out of range error while copying into pgadmin
- Cross join error with unnest array and user supplied data
- getting error when delete and the table does not have data
- How to convert JSON data into table and store into Postgres DB using Node JS?
- how to insert and update data into postgresql from node js using if condition
- Datamapper and Postgres lost data and error using Sinatra
- DB/SQL best practice: Validate data before insert, or TRY to insert and use error message
- When button is clicked "Undefined" data is being written to the DB (Angular, Jade, Heroku, Node and PostgreSQL are being used)
- Error while executing R commands in Java for accessing data from PostgreSQL and doing computation
- node and express - how to use fake data
- Spring data hibernate upsert transaction error @TransactionalEventListener and @Transactinal
- What is the correct syntax for mixed integers and letters in sqlalchemy to avoid Data Error
- Get 404 error when POST data to a foreign key field with express and sequelize
- ltree postgres type using spring data jpa -- geting syntax error after defining a function and cast within postgres
More questions with similar tag
- Rails db:create using PostgreSQL return PG::ConnectionBad: could not connect to server: Connection refused
- ETL tool or ad-hoc solutions?
- Measure the time it takes to execute a PostgreSQL query
- Invalid JDBC-Url: Driver org.postgresql.Driver claims to not accept jdbcUrl, jdbc:postgresql://${DB_ADDR_ALIAS}:${DB_PORT}/${DB_NAME}
- PostgreSQL date value changes to next day after 5 PM PST
- Saving data to Postgres from AWS Lambda
- Number of queries executed over psycopg2 connection
- pg_dump from remote server to localhost
- PostgreSQL: Getting STRING_AGG to respect the ordering from a CTE
- Rails: PG::UndefinedTable: ERROR: relation "..." does not exist
- Postgres function return unknown number of columns
- Why should we use rollback in sql explicitly?
- Converting a timestamp in milliseconds in Postgres
- PostgreSQL : CAST column only if exists
- postgresql 11 ERROR: syntax error at or near "`"
- Link two volumes, container not start
- Does unique constraint on multiple columns create index on each column
- Is there any way to update this column faster using PostgreSQL
- sails.js -postgresql returning string value instead of integer for bigint fields
- Connect to a PostgreSQL database on a Docker container
- Microsoft Identity Framework assigning roles to user error with Postgres Database - The CancellationTokenSource has been disposed
- Foreign Key Constraint Failed on Index Field Prisma Delete
- Retrieve ID python
- Convert postgres bytea string into php byte string
- PostgreSQL update statement to substring a column value
- Elasticsearch, Chewy, Postgres, and Apartment Multi-Tenancy
- Creating text string gets wrong output (postgresql)
- Mac + virtualenv + pip + postgresql = Error: pg_config executable not found
- Safely drop a user in Postgres
- PostgreSQL 11.5 insert or update (every operation should add the field value)
Source:
stackoverflow.com