Skip to content

Instantly share code, notes, and snippets.

@shark-h
Created September 4, 2019 10:14
Show Gist options
  • Save shark-h/02a1d1a06d28c24a20c9488fea654062 to your computer and use it in GitHub Desktop.
Save shark-h/02a1d1a06d28c24a20c9488fea654062 to your computer and use it in GitHub Desktop.
// SYNC WITH HASURA ON USER CREATE
exports.processSignUp = functions.auth.user().onCreate(async user => {
const id = user.uid;
const email = user.email;
const name = user.displayName || "No Name";
const mutation = `mutation($id: String!, $email: String, $name: String) {
insert_users(objects: [{
id: $id,
email: $email,
name: $name,
}]) {
affected_rows
}
}`;
try {
const data = await client.request(mutation, {
id: id,
email: email,
name: name
})
return data;
} catch (e) {
throw new functions.https.HttpsError('sync-failed');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment