admin.auth().signInWithVerifiedToken(decodedToken)
.signInWithIdToken(unverifiedToken)
admin.auth().verifyIdToken(idTokenSentFromClient)
.then(function(decodedToken) {
var uid = decodedToken.uid;
admin.auth().createCustomToken(uid)
.then(function(customToken) {
firebase.auth().signInWithCustomToken(token).then(() => {
// can now get user data..
})
})
})
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/1a6308bc-ce2f-4133-9edd-c489b1a884d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
admin.initializeApp(..., databaseAuthVariableOverride: 'someUid' )
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/1a6308bc-ce2f-4133-9edd-c489b1a884d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
const config = { ... };
const admin = firebase.initializeApp(config);
admin.auth().verifyToken(...).then(function(decodedToken) {
var uid = decodedToken.uid;
const appAsUser = firebase.initializeApp(getUserCreds(uid), `as_user_${uid}`);
appAsUser.database().ref('foo').set('bar');
}
function getUserCreds(uid) {
return {
credential: config.credential,
databaseURL: config.databaseURL,
databaseAuthVariableOverride: {
uid: "my-service-worker"
}
}
}
Covered here, here, and here. I hope that helps!
☼, Kato
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/26ffac09-614b-49e4-ac93-d15d7ad5d51a%40googlegroups.com.
Oops, where "my-service-worker"
should have been uid
. Missed one : )
Error: Firebase app named "dxxxxxxxxxxxxxxxxxxx" already exists.
This means you called initializeApp() more than once with the same app name as the second argument.
Make sure you provide a unique name every time you call initializeApp()
const clientMap = new Map()
function getScopedClient(uid) { if (clientMap.has(uid)) { return clientMap.get(uid) } const client = admin.initializeApp({ ..., databaseAuthVariableOverride: { uid } }, uid) clientMap.set(uid, client) return client}
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/26ffac09-614b-49e4-ac93-d15d7ad5d51a%40googlegroups.com.
--
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/3c527cfc-2b8e-4245-b9db-222d536e87c4%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/3c527cfc-2b8e-4245-b9db-222d536e87c4%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/3c527cfc-2b8e-4245-b9db-222d536e87c4%40googlegroups.com.
If you’re working with cloud functions, you can access event.data.ref
, which is already authenticated as the user who triggered the function call. That might be ideal for your use case.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/04e9b308-3d0c-4e52-bf2a-df3d54e81a14%40googlegroups.com.
functions.https.onRequest((req, res) => {... })
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/04e9b308-3d0c-4e52-bf2a-df3d54e81a14%40googlegroups.com.
In that case, you can just use limited privileges via setDatabaseVariableOverride(). Pretty sure this is answered on Stack Overflow already, but for the sake of convenience, I’ll just answer in simplified form here:
const extend = require('node.extend');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const config = functions.config().firebase;
// later inside your function
let userConf = extend({databaseAuthVariableOverride: userId}, config);
const ref = admin.initializeApp(userConf, userId).database.ref();
☼, Kato
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/7dc5a4e9-615a-4e39-8992-0100387ed0c1%40googlegroups.com.