Unhandled rejection error: password authentication failed for user "user" - node.js

I have a postgres datatbase set up and I installed PostgreSQL and knex.js in my node.js server file and added the code to connect to my database but everytime I use postman to see if im able to add users I get this error message
const db= knex
({
client
:'pg',
connection:{
host:'127.0.01',
user:'',
password:'',
database:'smartbrain'
}
});
app.post('/register',(req,res)=>{
const {email,name,password}=req.body;
db('user').insert({
email:email,
name:name,
joined:new Date()
})
.then(console.log())

Related

Error with pg-connection-string and sequelize in a React application

I am trying to use the sequelize ORM with a React application. I've installed the sequelize and pg-connection-string packages, but I am getting an error when trying to connect to the database. The error message is:
ERROR in ./node_modules/pg-connection-string/index.js 4:9-22
Module not found: Error: Can't resolve 'fs'
I've tried uninstalling and reinstalling the packages, clearing the npm cache, and using a different version of the packages, but I am still getting the same error.
I am using the following versions:
React: 16.13.1
Sequelize: 6.3.5
pg-connection-string: 2.0.0
Here is my code:
const Sequelize = require('sequelize');
const sequelize = new Sequelize('texteditor', 'root', '', {
host: 'localhost',
dialect: 'mysql'
});
const Database = sequelize.define('database', {
title: {
type: Sequelize.STRING
},
content: {
type: Sequelize.TEXT
}
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
sequelize.sync();
I would greatly appreciate any help or suggestions on how to resolve this issue.
So typically you do not connect to databases in the UI layer of an application. Likely the reason it can't retrieve the fs module is that you're running in a browser, where the sequelize package expects you to be using the node runtime. This is where you would build a backend server using Node.JS, which would connect to the DB and in turn respond to the UI with the information it needs.

Created database specific user but unable to connect with database name in mongo compass and node js application as well

I have a mongodb in linux server
I have created a user for specific database and user successfully created.
db.createUser(
{
user: “user1",
pwd: “user123",
roles: [ { role: "readWrite", db: “Products" }]
}
)
When I try to connect with credential and database in mongo compass showing invalid credential but when I go without database name only credential working fine and I'm able to access database as well.
I want to connect credential and database in mongo compass and want to connect in node js application as well
My nodejs connection code is
const url = 'mongodb://user1:user123#IP:27017/?authMechanism=DEFAULT';
mongoose.connect(url,{ dbName: 'Products' }, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
const con = mongoose.connection
con.on('open', () => {
console.log('connected...')
})
Node js code throwing error as
MongoNetworkError: failed to connect to server [IP:27017] on first connect [MongoNetworkTimeoutError: connection timed out

Firebase admin SDK getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND"

I'm trying to set up the admin sdk and also created a new private key. I even reverted back to an old version with only the admin sdk and it won't work. Is there anything which could be cached on my device?
Nest application successfully started NestApplication true
Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND". Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
at FirebaseAppError.FirebaseError [as constructor] (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseAppError (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:122:28)
at /Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/firebase-app.js:121:23
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at /Users/user/Documents/Dev/project/demo/node_modules/#nestjs/core/router/router-execution-context.js:44:28
at /Users/user/Documents/Dev/project/demo/node_modules/#nestjs/core/router/router-proxy.js:8:17 ExceptionsHandler
This is how I'm trying to use both packages:
import * as firebase from 'firebase-admin';
import * as serviceAccount from '../../firebase_credentials.json';
const config = {
type: serviceAccount.type,
projectId: serviceAccount.project_id,
privateKeyId: serviceAccount.private_key_id,
privateKey: serviceAccount.private_key,
clientEmail: serviceAccount.client_email,
clientId: serviceAccount.client_id,
authUri: serviceAccount.auth_uri,
tokenUri: serviceAccount.token_uri,
authProviderX509CertUrl: serviceAccount.auth_provider_x509_cert_url,
clientC509CertUrl: serviceAccount.client_x509_cert_url,
};
if (!firebase.apps.length) {
firebase.initializeApp(config);
}
export const firebaseAuth = firebase.auth();
export function create(email: string, password: string) {
firebaseAuth.createUser({
email: email,
emailVerified: false,
password: password,
displayName: email,
disabled: false,
})
.then( (userRecord) => {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord.uid);
})
.catch((error) => {
console.log('Error creating new user:', error);
});
}
What should I try to get this resolved?
Thanks for any help
You can't use both the Admin SDK and the regular Firebase JavaScript SDK in a single application. If the app runs in a potentially untrusted environment, you should use the regular JavaScript SDK. If it runs in a trusted environment (such as your development machine, a server you control, or Cloud Functions) you can use either the JavaScript SDK or the Admin SDK for that environment (in your case for Node.js).

Unable to connect to Realm Object Server using NodeJs

I've installed Realm Object Server using the docker container method on a VM on the google cloud platform. The container is running and I am able to connect in a browser and see the ROS page. I am able to connect to it using Realm Studio and add a user.
I have a nodeJS app running locally on a Mac and I'm trying to use that to sign in and write to realm on the server. When I run the app I get an error and the user returned is an empty object. Not sure what I'm doing wrong.
I'm new to NodeJS.
Code:
var theRealm;
const serverUrl = "http://xx.xx.xx.xx:9080";
const username = "xxxx";
const password = "xxxx";
var token = "long-token-for-enterprise-trial";
Realm.Sync.setFeatureToken(token);
console.log("Will log in user");
Realm.Sync.User.login(serverUrl, username, password)
.then(user => {
``
// user is logged in
console.log("user is logged in " + util.inspect(user));
// do stuff ...
console.log("Will create config");
const config = {
schema:[
schema.interventionSchema,
schema.reportSchema
],
sync: {
user: user,
url: serverUrl
}
};
console.log("Will open realm with config: " + config);
const realm = Realm.open(config)
.then(realm => {
// use the realm instance here
console.log("Realm is active " + realm);
console.log("Will create Realm");
theRealm = new Realm({
path:'model/realm_db/theRealm.realm',
schema:[
schema.interventionSchema,
schema.reportSchema
]
});
console.log("Did create Realm: " + theRealm);
})
.catch(error => {
// Handle the error here if something went wrong
console.log("Error when opening Realm: " + error);
});
})
.catch(error => {
// an auth error has occurred
console.log("Error when logging in user: " + error);
});
Output:
Will log in user
Server is running...
user is logged in {}
Will create config
Will open realm with config: [object Object]
TypeError: Cannot read property 'token_data' of undefined
at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
TypeError: Cannot read property 'token_data' of undefined
at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Error # user-methods.js:203:49
const tokenData = json.access_token.token_data;
json is:
{ user_token:
{ token: 'xxxxxxxx',
token_data:
{ app_id: 'io.realm.Auth',
identity: 'xxxxxxx',
salt: 'xxxxxxxx',
expires: 1522930743,
is_admin: false } } };
So json.access_token.token_data is undefined but json. user_token.token_data would not be.
I would suggest you to try the ROS connection with realm studio in that u can check logs as well which will help you to fix the error. If your still not able to fix then you can contact Realm support team even they helped me to fix the issue of ROS connection in Xamarin Forms using Docker.

Node.js MongoError: auth failed

I found out my website wasn't working anymore because i can't auth to my mongolab DB.
here is my code (it used to work for months):
var mongoose = require('mongoose');
mongoose.connect('mongodb://USER:PASSWORD#ds053419.mongolab.com:53419/jobinfest',
function(err) {
console.log(err);
if (err) { throw err; }
}
);
I have this error:
{ [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
But i can access the db via mongolab and :
mongo ds053419.mongolab.com:53419/jobinfest -u USER -p PASSWORD
I tried to create new users, even a new db. This way of connection seems to not work anymore
In your code be sure you are replacing USER:PASSWORD with your actual username and password.
mongodb://USER:PASSWORD#ds053419.mongolab.com:53419/jobinfest

Resources