[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-30 UTC。"],[],[],null,["To help you help your users control their data, the Firebase team created a library that simplifies two common user data processes:\n\n- `clearData`: deletes a user's data from specific Firebase services (currently\n Realtime Database, Firestore, and Storage) when they delete their account\n through Firebase Authentication.\n\n- `exportData`: saves a copy of a user's data from Firebase services to a JSON string, and uploads it to Cloud Storage so they can easily download it for themselves.\n\nKeep reading to find out how to add the functions to your app, or jump right in to the code at the\n[Firebase user privacy GitHub repo](https://github.com/firebase/user-privacy).\n| **Note:** **The `clearData` and `exportData` functions are a convenient way to manage data organized under a single user ID.** If you use more complicated data structures, for example, message responses nested under another user's ID, you may need more advanced patterns for your clear and export functions.\n\nAdd `clearData` or `exportData` to your app\n\nThe `clearData` and `exportData` functions in the library are implemented as Cloud Functions that operate on data in Realtime Database, Cloud Storage, and Cloud Firestore. Adding the functions in your own app is a three step process:\n\n1. Edit the library's `user_privacy.json` file to reflect your app's Realtime Database, Cloud Firestore, and Cloud Storage schema.\n2. Deploy `clearData` and `exportData` as Cloud Functions.\n3. Implement triggers for the functions in your app.\n4. Secure `clearData` data with storage rules.\n\nEdit the library's `user_privacy.json` file\n\nTo get started, clone or download the [Firebase user privacy GitHub repo](https://github.com/firebase/user-privacy).\n\nWhen you've done that, open `functions/user_privacy.json` in a text editor. The json file has a series of customizable paths that the `clearData` and `exportData` functions use to find your app's data in Realtime Database, Cloud Firestore, and Cloud Storage. If your app only uses one or two of those services, start by deleting the JSON objects associated with the unused services.\n\nWith the objects gone, you can begin to replace the remaining services' placeholder values with the actual data structures your app uses.\n\nAdd Realtime Database paths to user data\n\nTo customize `user_privacy.json` for your app's Realtime Database instance, replace the list of placeholder strings under `\"database\"` with actual paths to user data: \n\n```gdscript\n...\n \"database\": {\n \"clear\": [\n \"/users/UID_VARIABLE\", // Replace with your\n \"/admins/UID_VARIABLE\" // actual RTDB paths\n ],\n \"export\": [\n \"/users/UID_VARIABLE\", // Replace with your\n \"/admins/UID_VARIABLE\" // actual RTDB paths\n ]\n },\n...\n```\n\nIf you only want to add one of the functions to your app, you can delete the other function's object, instead of filling it in with your data.\n\nAdd Cloud Firestore objects containing user data\n\nTo customize `user_privacy.json` for your app's Cloud Firestore instance, replace the list of placeholder objects under `\"firestore\"` with actual Cloud Firestore objects containing user data: \n\n```gdscript\n...\n \"firestore\": {\n \"clear\": [\n {\"collection\": \"users\", \"doc\": \"UID_VARIABLE\", \"field\": \"name\"},\n {\"collection\": \"users\", \"doc\": \"UID_VARIABLE\"}, // Replace with your\n {\"collection\": \"admins\", \"doc\": \"UID_VARIABLE\"} // actual Firestore paths\n ],\n \"export\": [\n {\"collection\": \"users\", \"doc\": \"UID_VARIABLE\", \"field\": \"name\"},\n {\"collection\": \"users\", \"doc\": \"UID_VARIABLE\"}, // Replace with your\n {\"collection\": \"admins\", \"doc\": \"UID_VARIABLE\"} // actual Firestore paths\n ]\n },\n...\n```\n\nIf you only want to add one of the functions to your app, you can delete the other function's object, instead of filling it in with your data.\n\nAdd the Cloud Storage bucket and file name with user data\n\nTo customize `user_privacy.json` for your app's Cloud Storage instance, replace the placeholder storage bucket and file name under `\"storage\"` with the actual values: \n\n```gdscript\n...\n \"storage\": {\n \"clear\": [ // Replace with your actual storage data\n [\"clear-export.appspot.com\", \"UID_VARIABLE/sample_data.json\"],\n [\"clear-exportappspot.com\", \"UID_VARIABLE\"]\n ],\n \"export\": [ // Replace with your actual storage data\n [\"clear-export.appspot.com\", \"UID_VARIABLE/sample_data.json\"]\n ]\n },\n...\n```\n\nIf you only want to add one of the functions to your app, you can delete the other function's object, instead of filling it in with your data.\n\nDeploy `clearData` and `exportData` as Cloud Functions\n\nIf you're not familiar with Cloud Functions yet, read up on how to use them in the [Cloud Functions Get Started guide](/docs/functions/get-started).\n\nOnce you're comfortable with Cloud Functions, add the `clearData` and `exportData` functions to your project:\n\n1. Copy your customized `user_data.json` to your `functions` directory.\n2. Copy code from the user privacy library's [`index.js`](https://github.com/firebase/user-privacy/blob/master/functions/index.js) to your project's `index.js`.\n - If you're not using `clearData`, omit the `clearData`, `clearDatabaseData`, `clearFirestoreData`, and `clearStorageData` functions.\n - If you're not using `exportData`, omit the `exportData`, `exportDatabaseData`, `exportFirestoreData`, and `exportStorageData` functions.\n3. Deploy your functions.\n\nImplement triggers for `clearData` and `exportData`\n\nEach function requires a different trigger:\n\n- `clearData`: triggered when a user deletes their account through Authentication.\n- `exportData`: triggered by an HTTP request.\n\nImplement a `clearData` trigger\n\nTo trigger a `clearData` event, you need to use a method from Authentication. If you\nhaven't done it yet, add Authentication to your app: [Apple platforms](/docs/auth/ios/start), [Android](/docs/auth/android/start), or [web](/docs/auth/web/start).\n\nThen, add a way to invoke the Authentication SDK's `delete` method for your platform: \n\niOS+ \n\n FirebaseAuth.User.delete { error in\n if let error = error {\n print(\"Error deleting user: \\(error)\")\n }\n }\n\nAndroid \n\n FirebaseAuth.getCurrentUser().delete();\n\nWeb \n\n firebase.auth().currentUser.delete().catch(function(error) {\n if (error.code === 'auth/requires-recent-login') {\n window.alert('Please sign-in and try again.');\n firebase.auth().signOut();\n }\n });\n\nImplement an `exportData` trigger\n\nTo implement an `exportData` trigger, add a button or link to your app that invokes\nthe function via an HTTP request. Read more about invoking functions\nover HTTP in [Call functions via HTTP requests](/docs/functions/http-events).\n\nRequest details:\n\n- Type: `POST`\n- URL: `https://us-central1-\u003cvar\u003ePROJECT-ID\u003c.var\u003e.cloudfunctions.net/exportData`\n- Body: `\u003cvar\u003eCURRENT_USER'S_UID\u003c/var\u003e`\n\nInvoke the function directly in Firebase Hosting\n\nIf your app is a web app hosted on Firebase Hosting, you can invoke your\n`clearData` function through a `rewrite` entry in the site's `firebase.json` file: \n\n \"hosting\": {\n \"rewrites\": [\n {\"source\": \"/exportData\", \"function\": \"exportData\"}\n ]\n }\n\nSecure `exportData` data with storage rules\n\nTo keep your users' exported data private, add Cloud Storage\nrules that restrict access to the exporting user.\n\n1. Visit **Storage** in the [Firebase console](//console.firebase.google.com/project/_/storage).\n2. Open the **Rules** tab.\n3. Paste the following rule, then click **Publish**:\n\n```gdscript\nservice firebase.storage {\n match /b/{bucket}/o {\n match /exportData {\n // Only allow access to the user who requested the export\n match /{uid} {\n allow read, write: if request.auth.uid == uid\n }\n match /{uid}/{path=**} {\n allow read, write: if request.auth.uid == uid\n }\n }\n // Other application rules...\n }\n}\n```\n| **Note:** **Check for overlapping Cloud Storage rules.** Broader Cloud Storage access rules override more restrictive ones. Check that you don't have a preexisting rule that would invalidate your new rule."]]