Last active
July 24, 2020 09:30
-
-
Save shinriyo/464cbb40d1377d6b76d2a93a76a1d491 to your computer and use it in GitHub Desktop.
Sync Document for delete (AddSearch with Firestore, Functions, TypeScript)
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 { 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