npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sonicgarden/auth-backup-firebase-functions

v1.0.4

Published

Firebase Authentication Backup for Firebase Cloud Functions

Downloads

1,532

Readme

auth-backup-firebase-functions

Firebase Authentication Backup for Firebase Cloud Functions

Installation

npm install --save @sonicgarden/auth-backup-firebase-functions
// or
yarn add @sonicgarden/auth-backup-firebase-functions

Setup

Google Cloud のリソースの作成を行う。

パッケージと共にインストールされる auth-backup-firebase-setup というスクリプトで作成可能。

auth-backup-firebase-setup <PROJECT_ID> [<KMS_LOCATION> <BUCKET_LOCATION>]

手動で作る場合は以下を参照。

Cloud Key Management Service setup

バックアップを KMS で暗号化するための初期設定を行う。

$ export PROJECT_ID=<YOUR_PROJECT_ID>
$ gcloud services enable cloudkms.googleapis.com --project "${PROJECT_ID}"
$ gcloud kms keyrings create --location=asia-northeast1 firebase-authentication-keyring --project "${PROJECT_ID}"
$ gcloud kms keys create --location=asia-northeast1 \
  --keyring=firebase-authentication-keyring \
  --purpose=encryption \
  --rotation-period=90d \
  --next-rotation-time="$(date -I -d "90 days")T00:00:00Z" \
  firebase-authentication-backup-key \
  --project "${PROJECT_ID}"

Cloud Storage setup

バックアップの保存先である Storage のバケットを作成する。

$ gcloud storage buckets create "gs://${PROJECT_ID}-authentication-backups" \
  --project="${PROJECT_ID}" \
  --default-storage-class=COLDLINE \
  --location=ASIA \
  --uniform-bucket-level-access

バケットのライフサイクルの設定を行う。 「オブジェクトが作成されてから 30 日以降」の条件で、「オブジェクトの削除」をするよう設定する。

$ echo '{ "lifecycle": { "rule": [{ "action": { "type": "Delete" }, "condition": { "age": 30 } }] } }' > lifecycle.json
$ gcloud storage buckets update "gs://${PROJECT_ID}-authentication-backups" --lifecycle-file=lifecycle.json

Service Account setup

Functions を実行するサービスアカウントを作成します。 (もしくは Functions を実行する既存のサービスアカウントに以下ロールを付与する)

# サービスアカウント作成
$ gcloud iam service-accounts create backup-auth --display-name="backup-auth" --project "${PROJECT_ID}"

# バックアップ用カスタムロールを作成
$ gcloud iam roles create firebaseAuthBackup \
  --project "${PROJECT_ID}" \
  --title="Firebase Auth backup" \
  --description="Custom role for Firebase Auth backup" \
  --permissions="firebaseauth.users.get,firebaseauth.configs.getHashConfig" \
  --stage=GA

# 作成したサービスアカウントにバックアップ用カスタムロールを付与
$ gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:backup-auth@${PROJECT_ID}.iam.gserviceaccount.com" \
  --role "projects/${PROJECT_ID}/roles/firebaseAuthBackup"

# 作成したサービスアカウントに「Storage オブジェクト作成者」を付与
$ gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:backup-auth@${PROJECT_ID}.iam.gserviceaccount.com" \
  --role roles/storage.objectCreator

# 作成したサービスアカウントに「クラウド KMS 暗号鍵の暗号化ロール」を付与
$ gcloud kms keys \
  add-iam-policy-binding \
  --location=asia-northeast1 \
  --keyring=firebase-authentication-keyring \
  firebase-authentication-backup-key \
  --member="serviceAccount:backup-auth@${PROJECT_ID}.iam.gserviceaccount.com" \
  --role=roles/cloudkms.cryptoKeyEncrypter \
  --project "${PROJECT_ID}"

Service Account setup (for restore)

Restore を実行するためのサービスアカウントを作成。 Restoreが必要になった時に、このサービスアカウントを作成し、そのサービスアカウントを利用してscript等でRestore関数を実行する。

# サービスアカウント作成
$ gcloud iam service-accounts create restore-auth --display-name="restore-auth" --project "${PROJECT_ID}"

# 作成したサービスアカウントに「Identity Platform 管理者」を付与
$ gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:restore-auth@${PROJECT_ID}.iam.gserviceaccount.com" \
  --role roles/identityplatform.admin

# 作成したサービスアカウントに「Storage オブジェクト閲覧者」を付与
$ gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:restore-auth@${PROJECT_ID}.iam.gserviceaccount.com" \
  --role roles/storage.objectViewer

# 作成したサービスアカウントに「クラウド KMS 暗号鍵の暗号化ロール」を付与
$ gcloud kms keys \
  add-iam-policy-binding \
  --location=asia-northeast1 \
  --keyring=firebase-authentication-keyring \
  firebase-authentication-backup-key \
  --member="serviceAccount:restore-auth@${PROJECT_ID}.iam.gserviceaccount.com" \
  --role=roles/cloudkms.cryptoKeyEncrypterDecrypter \
  --project "${PROJECT_ID}"

Usage

import { backupAuth as _backupAuth } from '@sonicgarden/auth-backup-firebase-functions';
import { onSchedule } from 'firebase-functions/v2/scheduler';

export const backupAuth = onSchedule(
  {
    schedule: '0 1 * * *',
    region: 'asia-northeast1',
    timeZone: 'Asia/Tokyo',
    serviceAccount: `backup-auth@${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`,
  },
  async (event) => {
    await _backupAuth({ region: 'asia-northeast1' });
  }
);

Parameters

backupAuth

| parameter | required | default value | description | | ----------- | -------- | -------------------------------------- | ----------- | | region | required | - | KMS のリージョン | | projectId | optional | process.env.GCLOUD_PROJECT | プロジェクト ID | | bucketName | optional | ${process.env.GCLOUD_PROJECT}-authentication-backups | GCS バケット名 | | encrypt | optional | true | バックアップファイルを暗号化するか | | keyringName | optional | firebase-authentication-keyring | KMS キーリング名 | | keyName | optional | firebase-authentication-backup-key | KMS キー名 |

restoreAuth

| parameter | required | default value | description | | -------------------- | -------- | -------------------------------------- | ----------- | | region | required | - | KMS のリージョン | | backupFilePath | required | - | GCS 内のバックアップファイルパス | | projectId | optional | process.env.GCLOUD_PROJECT | プロジェクト ID | | bucketName | optional | ${process.env.GCLOUD_PROJECT}-authentication-backups | GCS バケット名 | | encrypted | optional | true | バックアップファイルが暗号化されているか | | keyringName | optional | firebase-authentication-keyring | KMS キーリング名 | | keyName | optional | firebase-authentication-backup-key | KMS キー名 | | destinationProjectId | optional | process.env.GCLOUD_PROJECT | リストア先のプロジェクト ID | | hashParams | optional | - | パスワードハッシュのパラメータ(hashAlgo, hashKey, saltSeparator, rounds, memCost) |

npm publish

git tag -a v1.0.0 -m "My first version v1.0.0"
git push origin tags/v1.0.0
npm publish --access=public

update

npm version patch # or minor or magor
git push origin tags/v1.0.1
npm publish --access=public