I faced a problem when I used .env file in node.js - javascript

In my node.js project, I want to use environment variables for saving MongoDB's user name and password. When I directly use username and password then it is working completely. But when I used template string and process.env.varName then I got bad auth: Authentication failed error message.
ok: 0,<br/>
code: 8000,<br/>
codeName: 'AtlasError',<br/>
[Symbol(errorLabels)]: Set(0)<br/>
{}

Related

Unit testing with firebase auth emulator requires real service account?

We are using the firebase emulators to write integration tests. One of our functions modifies the claims on a user. As such, our test checks to see if the claim has been added. In our test, we call the following function:
admin.auth().getUser(user.userId)
Our intention is to then check the claims. Unfortunately, when this function is called, we get an error.
(node:96985) UnhandledPromiseRejectionWarning: 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".
Keep in mind we are running against the local auth emulator, not a cloud service. We found an issue on github which seems to be related: https://github.com/firebase/firebase-tools/issues/1708
Unfortunately, the recommended course of action in that issue is to use an actual service account file from an actual cloud service. We do not check such files into our repos as this would be a security hazard. Does anyone know of a better way to deal with this situation?
In case it is relevant, we also get the following warning:
{"severity":"WARNING","message":"Warning, FIREBASE_CONFIG and
GCLOUD_PROJECT environment variables are missing. Initializing
firebase-admin will fail"}

I cant connect to the database through the microsoft login by using code in nuget console code

I am trying to connect the database file for web application. i put the code in Nuget console to connect the database but my microsoft account can't get it as login fails. What is the reason behind the failure of login?
Tools->Nuget Package Manager->Package Manager Console, type the following command:
PM> Scaffold-DbContext "server=alpha;Trusted_Connection=True;MultipleActiveResultSets=true;database=StDb2Sql;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
PM>
After executing some files I received message:
Cannot open database "StDb2Sql" requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\kartikpatel2188#gmail.com'.
Could it be that you've prefixed it with a Domain: MicrosoftAccount\
kartikpatel2188#gmail.com
Use your email: kartikpatel2188#gmail.com

adonisjs migration issue with mysql

I'm trying to get the hang of adonisjs through this tutorial
I set up everything properly as instructed in there but I run into a problem when I type adonis migration:run.
The error I get on Terminal is Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'#'localhost' (using password: NO)
I have 0 experience with mysql and this confuses me. I'd appreciate some guidance/help here.
Cheers!
#katotopark, this means your MySQL server is rejecting the connection from the Adonisjs application. check for a file called (.env) in the root folder of your project and inside you will need to add the credentials for the connection the MySQL server. (probably user: root, password: the password you use when you installed MySQL)
your .env should look similar to this.
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root/or-another-mysql-user
DB_PASSWORD=your-database-user-password***
DB_DATABASE=the_name_of_your_database
Regards.

How to set up SSH Agent Forwarding in node.js (simple-ssh module)?

I am new to this node.js and using module simple-ssh for executing shell commands from my windows to remote server.
Whenever I run my code, the console curses me with [Error: Authentication failure. Available authentication methods: publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive].
I have already put an RSA private-key file, and set the Windows ENV variable SSH_AUTH_SOCK. But still it keeps giving the error.
Below is the code snippet which I wrote for simple-ssh:
var ssh = new SSH({
host: sshHost,
user: 'root',
timeout: 11000000,
key: require('fs').readFileSync("D:/Keys_pair_prvt_pub/rsa_key"),
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
});
When I am trying to SSH the remote from my windows cmd-prompt, it is giving me error:
$> ssh -A <myRemote.host.com>
ssh : The term 'ssh' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
Am I missing anything? If yes, then how do I overcome this ?
Any help will be appreciated :)
Thanks.
Your key needs to be added to ~/.ssh/authorized_keys on the server for your key to work.
mscdex npm package SSH2, which simple-ssh wraps, has this in the docs for using ssh.agent on windows:
`agent - string - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket."

Meteor mail not sending despite setting MAIL_URL environment variable

I'm getting this error message in the terminal "Mail not sent; to enable sending, set the MAIL_URL environment variable." despite setting MAIL_URL environment variable. After this message the whole mail content html gets dumped in the terminal. I'm using 2 meteor packages for sending email: yogiben:pretty-emails and email with mailgun api service.
Here's the source code for the mail config and sending email:
if Meteor.isServer
Meteor.startup ->
process.env.MAIL_URL = 'smtp://sandboxid.mailgun.org:mypassword#smtp.mailgun.org:587'
return
PrettyEmail.options =
from: 'primaryemail#gmail.com'
siteName: 'Meteor Test'
companyAddress: 'sdfsf, gdfg-df'
companyName: 'Code to Create'
companyUrl: 'http://example.com'
Accounts.sendVerificationEmail ->
Meteor.userId()
This file is kept inside Project_Directory/both/_config directory. I'm currently developing this app on local ubuntu server.
I think the call to sendVerificationEmail should be:
Accounts.sendVerificationEmail Meteor.userId()
as per the docs at http://docs.meteor.com/#/full/accounts_sendverificationemail
If that code is the exact code you're using, then you may be having issues because of the order in which each piece of code runs (callbacks run asynchronously). The startup callback will run after PrettyEmail.options and Accounts.sendVerificationEmail
If you indent those two sections as follows it should work as expected:
if Meteor.isServer
Meteor.startup ->
process.env.MAIL_URL = 'smtp://sandboxid.mailgun.org:mypassword#smtp.mailgun.org:587'
PrettyEmail.options =
from: 'primaryemail#gmail.com'
siteName: 'Meteor Test'
companyAddress: 'sdfsf, gdfg-df'
companyName: 'Code to Create'
companyUrl: 'http://example.com'
Accounts.sendVerificationEmail Meteor.userId()
Failing that it may also be worth setting MAIL_URL before running the app, for example:
MAIL_URL="smtp://sandboxid.mailgun.org:mypassword#smtp.mailgun.org:587" meteor
EDIT:
Your example code is not secure: If you are keeping this code in the 'both' directory, then anyone accessing your website will be able to see your mailgun credentials. You should put server code in the 'server' directory or at the very least set the MAIL_URL outside of your code as shown above.
I came across the same error. The trick was to not include the MAIL_URL in the application, but in the terminal where you run meteor itself.
Use the following command to run meteor:
MAIL_URL="smtp://postmaster#sandbox****.mailgun.org:XXXX#smtp.mailgun.org:587" meteor
I tried this on Ubuntu Terminal, hence should work on Mac as well.

Categories

Resources