Skip to content

Instantly share code, notes, and snippets.

@Rob117
Created March 5, 2019 10:21
Show Gist options
  • Save Rob117/44cffe72627b7da88b282665b7915036 to your computer and use it in GitHub Desktop.
Save Rob117/44cffe72627b7da88b282665b7915036 to your computer and use it in GitHub Desktop.
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
export const signUp = functions.https.onRequest(async (request, response) => {
admin.initializeApp()
if (request.method !== "POST") {
return response.status(400).send();
}
var data = request.body;
if (data.token !== "TOKEN FROM ENV HERE") {
return response.status(401).send();
}
let user
try {
user = await admin.auth().createUser({
email: data.email,
password: data.password,
emailVerified: true
})
} catch (err) {
return response.status(500).send(err)
}
let info
try {
await admin.auth().setCustomUserClaims(user.uid, { valid: true, paid: false })
} catch (err) {
return response.status(500).send(err)
}
info = await admin.auth().getUser(user.uid)
return response.send(info)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment