Created
September 12, 2022 14:24
-
-
Save cmjunior/7dbb13d461736e582d9befc45e3779b5 to your computer and use it in GitHub Desktop.
- Cloud Function para criar um usuário no Google Firebase Authentication
This file contains hidden or 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
import * as admin from 'firebase-admin'; | |
import * as functions from "firebase-functions"; | |
admin.initializeApp(); | |
exports.createUser = functions.https.onRequest( (req, res) => { | |
let { email, password } = req.body | |
if ( !(email || password) ) { | |
res.status(500).json({ | |
status: 'error', | |
error: 'Você precisa fornecer o email e a senha!' }) | |
} else { | |
admin.auth().createUser({ | |
email, password | |
}).then( userRecord => { | |
res.status(201).json({ | |
result: 'success', | |
message: 'Usuario criado com sucesso!', uid: userRecord.uid }) | |
}).catch( error => { | |
res.status(500).json({status: 'error', error }) | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment