Created
March 5, 2019 10:21
-
-
Save Rob117/44cffe72627b7da88b282665b7915036 to your computer and use it in GitHub Desktop.
This file contains 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 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