Skip to content

Instantly share code, notes, and snippets.

@shinriyo
Last active July 24, 2020 09:30
Show Gist options
  • Select an option

  • Save shinriyo/464cbb40d1377d6b76d2a93a76a1d491 to your computer and use it in GitHub Desktop.

Select an option

Save shinriyo/464cbb40d1377d6b76d2a93a76a1d491 to your computer and use it in GitHub Desktop.

Revisions

  1. shinriyo revised this gist Jul 24, 2020. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions user.onDelete.ts
    Original file line number Diff line number Diff line change
    @@ -7,14 +7,14 @@ export const userOnDeleteForAddSearch = functions.firestore
    const axios = require('axios');
    const documentId = event.id;

    const args = {
    withCredentials: true,
    custom_fields: {},
    headers: {
    "Content-Type": "application/json",
    }
    }

    // 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, {
  2. shinriyo revised this gist Jul 24, 2020. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions user.onDelete.ts
    Original file line number Diff line number Diff line change
    @@ -15,11 +15,10 @@ export const userOnDeleteForAddSearch = functions.firestore
    }
    }

    console.log('documentId:', documentId);
    console.log('siteKey:', siteKey);
    console.log('secretKey:', secretKey);

    axios.delete(`${baseURL}/v2/indices/${siteKey}/documents/${documentId}`, args, {
    // 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,
  3. shinriyo revised this gist Jul 24, 2020. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions user.onDelete.ts
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,7 @@ export const userOnDeleteForAddSearch = functions.firestore
    console.log('documentId:', documentId);
    console.log('siteKey:', siteKey);
    console.log('secretKey:', secretKey);
    // DELETE /v2/indices/{index public key}/documents/{document id}
    // 対象を消す

    axios.delete(`${baseURL}/v2/indices/${siteKey}/documents/${documentId}`, args, {
    // HTTP Basic Auth
    auth: {
  4. shinriyo created this gist Jul 24, 2020.
    39 changes: 39 additions & 0 deletions user.onDelete.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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;

    const args = {
    withCredentials: true,
    custom_fields: {},
    headers: {
    "Content-Type": "application/json",
    }
    }

    console.log('documentId:', documentId);
    console.log('siteKey:', siteKey);
    console.log('secretKey:', secretKey);
    // DELETE /v2/indices/{index public key}/documents/{document id}
    // 対象を消す
    axios.delete(`${baseURL}/v2/indices/${siteKey}/documents/${documentId}`, args, {
    // 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 ***")
    })
    });