Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. exports.auth = functions.https.onRequest((req, res) => {
  2. const email = req.body.email;
  3. const passcode = req.body.passcode;
  4.  
  5. admin.auth().getUserByEmail(email)
  6. .then(user => {
  7. return user.uid
  8. })
  9. .then(uid => {
  10. return admin.firestore().collection('contracts').where('uid', '==', uid).get()
  11. .then(data => {
  12. const contract = {uid: uid}
  13. data.forEach(doc => {
  14. if (doc.data().passCode == passcode) contract.id = doc.data().id
  15. })
  16.  
  17. return contract
  18. })
  19. })
  20. .then(data => {
  21. return admin.auth().createCustomToken(data.uid)
  22. .then(token => {
  23. res.send({token: token, contractId: data.id})
  24. })
  25. })
  26. .catch(err => res.send(err.message))
  27. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement