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).
Related
I have the following nodejs script.
const admin = require("firebase-admin")
admin.initializeApp({
credential: admin.credential.cert("./serviceAccountKey.json"),
databaseURL: "https://<ProjectID>.firebaseio.com/"
})
const uid = "5mP5FvjjCKcJ1IBXfV3rpChd3ob2"
admin
.auth()
.setCustomUserClaims(uid, { role: 'admin' })
.then(() => {
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
console.log(`Admin claim added to ${uid}`)
})
.catch((err) => console.log(err))
When I run the script I get the following error.
{
errorInfo: {
code: 'app/network-error',
message: 'Error while making request: connect ECONNREFUSED 127.0.0.1:9099. Error code: ECONNREFUSED'
},
codePrefix: 'app'
}
What am I doing wrong here?
Also, my firebase project has the spark plan.
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())
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.
I'm working on android app and I use node js back end and Firebase platform for my app, I manage users with firebase-auth, and the problem is when I register a new user to firebase-auth using node js I see this error.
This is the source code.
function registerUser(socket,io){
// retrieve data from android app
socket.on('userData',(data)=>{
console.log(data.email);
console.log(data.userName);
console.log(data.password);
// register new user using data.
admin.auth().createUser({
email: data.email,
password: data.password,
displayName: data.userName,
})
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log("Successfully created new user:", userRecord.uid);
const db = admin.database();
const ref = db.ref('users/');
const userid = ref.child(encodeEmail(data.email));
userid.set({
username: data.userName,
email: data.email,
password:data.password
}).then((error)=>{
console.log('successfully write in database real time ');
});
})
.catch(function(error) {
console.log("Error creating new user:", error);
});
});
}
and this is the error:
Error creating new user: { Error: www.googleapis.com network timeout. Please try again.
at FirebaseAppError.FirebaseError [as constructor] (/node_modules/firebase-admin/lib/utils/error.js:39:28)
at new FirebaseAppError (/firebase-admin/lib/utils/error.js:84:23)
at TLSSocket.<anonymous> (friend-chat-server/node_modules/firebase-admin/lib/utils/api-request.js:121:51)
at emitNone (events.js:105:13)
at TLSSocket.emit (events.js:207:7)
at TLSSocket.Socket._onTimeout (net.js:398:8)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
errorInfo:
{ code: 'app/network-timeout',
message: 'www.googleapis.com network timeout. Please try again.' } }
firebase added to node js successfully everything good but i don't know how to fix this . help please!
This is my code run on a node.js server. I have the proper access token obtained from OAuth2.0 protocol as defined in the Instagram developer page.
function getMedia(accessToken) {
var instagram = require('instagram-node').instagram();
instagram.use({
access_token: accessToken
});
instagram.user_self_media_recent(function(err, medias, pagination, remaining, limit) {
if(err) {
console.log(err);
}
console.log(medias);
});
}
I'm getting this in my error response:
{ Error: getaddrinfo ENOTFOUND api.instagram.com api.instagram.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.instagram.com',
host: 'api.instagram.com',
port: 443,
retry: [Function: retry] }
Does anyone know what this error response means?
Quick follow up. I was using Google's Firebase for my backend. On the "Spark" plan you get this warning:
Billing account not configured. External network is not accessible and
quotas are severely limited. Configure billing account to remove these
restrictions
I upgraded to "Blaze" plan and now retrieve data from Instagram.
The answer posted below suggests that I need to initialize the Instagram client with a client_id and client_secret, this is not true. I am getting media posts with just the access_token.
Thanks
When you initialize the instagram client you should use your app's client Id and client secret.
instagram.use({
client_id: INSTA_CLIENT_ID,
client_secret: INSTA_CLIENT_SECRET,
});
Then use the access token you have to authenticate the specific instagram user and request medias on their behalf.
instagram.use({
access_token: accessToken
});
instagram.user_self_media_recent(function(err, medias, pagination, remaining, limit) {
if(err) {
console.log(err);
}
console.log(medias);
});
When you first initialize your instagram node client you must use the authentication credentials that you receive from instagram when you register your app here.