Skip to content

Instantly share code, notes, and snippets.

@cmjunior
Created September 12, 2022 14:24
Show Gist options
  • Save cmjunior/7dbb13d461736e582d9befc45e3779b5 to your computer and use it in GitHub Desktop.
Save cmjunior/7dbb13d461736e582d9befc45e3779b5 to your computer and use it in GitHub Desktop.
- Cloud Function para criar um usuário no Google Firebase Authentication
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