const firebase = require('firebase')
const admin = require('firebase-admin')
const serviceAccount = require('./serviceAccountKey.json')
const secret = {
"PROJECT_ID": "xxx",
"API_KEY": "xxx"
}
firebase.initializeApp({
apiKey: `${secret.API_KEY}`,
authDomain: `${secret.PROJECT_ID}.firebaseapp.com`,
databaseURL: `https://${secret.PROJECT_ID}.firebaseio.com`,
storageBucket: `${secret.PROJECT_ID}.appspot.com`,
})
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: `https://${secret.PROJECT_ID}.firebaseio.com`,
})
Then
const auth = firebase.auth()
auth.signInAnonymously()
.then(_ => console.log('Signed in. ID:', auth.currentUser.uid))
const uid = user.uid
console.log('User ID:', uid)
user.getIdToken()
.then(token => console.log('Got a token:', token))
auth.signOut()
.then(token => console.log('Signed out'))
if (!auth.currentUser) {
console.log('Not signed in!')
}
auth.signInWithCustomToken(token)
.catch(error => console.log(error.code, error.message))
auth/invalid-custom-token The custom token format is incorrect. Please check the documentation.
auth.signInAndRetrieveDataWithCredential(token)
.catch(error => console.log(error.code, error.message))
auth/argument-error signInAndRetrieveDataWithCredential failed: First argument "credential" must be a valid credential.
auth.signInWithCredential(token)
.catch(error => console.log(error.code, error.message))
auth/argument-error signInWithCredential failed: First argument "credential" must be a valid credential.
admin.auth().verifyIdToken(token)
.then(data => {
console.log(data)
console.log('Signed in?', auth.currentUser !== null)
})
You would get data including uid
. Then what's next?