Skip to content

Instantly share code, notes, and snippets.

@alejovdev
Created July 27, 2020 12:08
Show Gist options
  • Save alejovdev/9defc69e7d56297630803eddf7e8e072 to your computer and use it in GitHub Desktop.
Save alejovdev/9defc69e7d56297630803eddf7e8e072 to your computer and use it in GitHub Desktop.
import * as functions from 'firebase-functions'
import * as service from './service.json'
import admin = require('firebase-admin')
const params = {
type: service.type,
projectId: service.project_id,
privateKeyId: service.private_key_id,
privateKey: service.private_key,
clientEmail: service.client_email,
clientId: service.client_id,
authUri: service.auth_uri,
tokenUri: service.token_uri,
authProviderX509CertUrl: service.auth_provider_x509_cert_url,
clientC509CertUrl: service.client_x509_cert_url,
}
admin.initializeApp({
credential: admin.credential.cert(params),
databaseURL: 'https://yourprojecturl.firebaseio.com',
})
export const getUserToken = functions.https.onCall(async (data) => {
try {
let res = await admin.auth().createCustomToken(data.uid)
return { error: false, data: res }
} catch (error) {
return { error: true, data: error }
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment