Created
June 3, 2021 21:07
-
-
Save gual/c60f0357570ba49fa4fdc7a8187fb5d3 to your computer and use it in GitHub Desktop.
Firebase server side token validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const firebaseAdmin = require('firebase-admin'); | |
const token = 'token_complete'; | |
console.log('Initializing app'); | |
firebaseAdmin.initializeApp({ | |
credential: firebaseAdmin.credential.applicationDefault(), | |
databaseURL: 'https://project-default-rtdb.firebaseio.com' | |
}); | |
console.log('To verify'); | |
firebaseAdmin | |
.auth() | |
.verifyIdToken(token) | |
.then(decodedToken => { | |
console.log('success'); | |
console.log(decodedToken); | |
console.log(decodedToken.uid); | |
}) | |
.catch(err => { | |
console.log('error'); | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment