I would like to add a button 'Login with google' to my app and I'm trying to do the authentication with firebase in node js. I didn't get any example from firebase official site, where the documentation is given for java script.
please find the code snippet below:
const firebaseAdmin = require('firebase-admin');
const serviceAccount = require('./SAK.json');
const FirebaseAuth = require('firebaseauth');
const authProvider = new FirebaseAuth("API_KEY");
const authToken = FirebaseAuth.initTokenMiddleware(serviceAccount);
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert(serviceAccount)
});
router.get('/loginWithGoogle/', (req,res) => {
authProvider.loginWithGoogle(authToken, function(err, result) {
if (err) {
console.log('err');
}
else {
console.log(result);
}
});
});
The authToken value is null i guess. I'm getting the below error :
TypeError: Cannot read property 'trim' of null at loginWithProviderID (/workspace/sodiumBackend/node_modules/firebaseauth/dist/providers/social-providers.js:22:23) at Object.loginWithGoogle (/workspace/sodiumBackend/node_modules/firebaseauth/dist/providers/social-providers.js:57:5) at FirebaseAuth.loginWithGoogle (/workspace/sodiumBackend/node_modules/firebaseauth/dist/index.js:61:25) at router.get (/workspace/sodiumBackend/src/routes/api/user.js:8:18) at Layer.handle [as handle_request] (/workspace/sodiumBackend/node_modules/express/lib/router/layer.js:95:5) at next (/workspace/sodiumBackend/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/workspace/sodiumBackend/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/workspace/sodiumBackend/node_modules/express/lib/router/layer.js:95:5)