Skip to content

Instantly share code, notes, and snippets.

@shinriyo
Last active July 24, 2020 09:30
Show Gist options
  • Save shinriyo/464cbb40d1377d6b76d2a93a76a1d491 to your computer and use it in GitHub Desktop.
Save shinriyo/464cbb40d1377d6b76d2a93a76a1d491 to your computer and use it in GitHub Desktop.
Sync Document for delete (AddSearch with Firestore, Functions, TypeScript)
import { index, baseURL, siteKey, secretKey } from './index';
import * as functions from 'firebase-functions'
export const userOnDeleteForAddSearch = functions.firestore
.document('users/{userId}')
.onDelete(async (event, context) => {
const axios = require('axios');
const documentId = event.id;
// needless
// const args = {
// withCredentials: true,
// custom_fields: {},
// headers: {
// "Content-Type": "application/json",
// }
// }
// auth is 2nd params. not 3rd!
// axios.delete(`${baseURL}/v2/indices/${siteKey}/documents/${documentId}`, args, {
axios.delete(`${baseURL}/v2/indices/${siteKey}/documents/${documentId}`, {
// HTTP Basic Auth
auth: {
username: siteKey,
password: secretKey,
}
})
.then((response: any) => {
console.log(response.data)
})
.catch((error: any) => {
console.log(error)
})
.then(function () {
console.log("*** finish ***")
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment