Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work in Progress: create user #183

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const User = require('./models/user');
const Goal = require('./models/goal');
const {isValidEmail} = require('./models/data-validators');
const {db} = require('./models/user');
var admin = require('firebase-admin');

exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
Expand All @@ -19,6 +20,49 @@ exports.helloWorld = functions.https.onRequest((request, response) => {
}
});

/**
* WIP: Create a new user
*
* Since the use of this app should be restricted to existing CVOEO clients, users
* cannot create their own account - the app does that for them. This is the second
* step in creating an account for users:
* 1) MoMM pulls csv data from OutcomeTracker and identifies new ReachUp clients
* 2) MoMM creates a new user in Firebase with the csv data
* 3) The new user opens the app for the first time and clicks "register"
* 4) The "register" behavior is actually the "forgot password" behavior; it walks
* the user through resetting the password for the firebase account we've created
*
curl -X POST \
http://localhost:5001/cvoeo-45350/us-central1/createAccount \
-H 'Content-Type: application/json' \
-d '{
"email": "micahm@gmail.com"
}'
*/
exports.createAccount = functions.https.onRequest((request, response) => {
console.info(`Let's try creating an account for ${request.body.email}!`);

// see: https://firebase.google.com/docs/auth/admin/manage-users#create_a_user
admin.auth().createUser({
email: request.body.email,
emailVerified: false,
phoneNumber: '+11234567890',
password: 'secretPassword',
displayName: 'John Doe',
photoURL: 'http://www.example.com/12345678/photo.png',
disabled: false
})
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord.email);
response.send({ status: 200, data: { userRecord }});
})
.catch(function(error) {
console.log('Error creating new user:', error);
response.send({ status: 500, error: error });
});
});

/*This firebase function is for testing purposes to be able to use a file saved locally as input.
To run this function, have a firebase server set locally then run the following command:
curl -X POST <local path to firebase fuunction> -H "Content-Type:application/json" -d '{"pathToFile":"<path to local file>"}'
Expand Down