0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

firebaseの初期設定 @yukilulu0229

Posted at

プロジェクトを追加

  • プロジェクト名決める

  • アナリティクスはなくてもよい

ウェブアプリに Firebase を追加

スクリーンショット 2024-01-26 9.46.21.png

  • webをクリック
  • 名前を決める
  • このアプリの Firebase Hosting デプロイするならチェック入れる

Authentication

スクリーンショット 2024-01-26 9.50.00.png

必要ならここを設定

  • 使いたいAuthを選択

  • 有効にする
    スクリーンショット 2024-01-26 9.52.21.png

  • プロジェクトのサポートメールを選択

Cloud Firestoreを使う

スクリーンショット 2024-01-26 9.54.37.png

  • ロケーションを選択
  • テストモードで開始する
  • ルール設定でデータを保存する期間を変える場合はif文以降を消す

スクリーンショット 2024-01-26 9.56.58.png

rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {

    // This rule allows anyone with your Firestore database reference to view, edit,
    // and delete all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // all client requests to your Firestore database will be denied until you Update
    // your rules
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2024, 2, 25);
    }
  }
}

: if request.time < timestamp.date(2024, 2, 25); の部分

プロジェクトの設定

スクリーンショット 2024-01-26 10.01.07.png

  • SDK の設定と構成の設定の通りやる

npm install firebase でインストール

  • src/firebase.tsを作成
  • 次に Firebase を初期化し、使用するプロダクトの SDK の利用を開始します。をコピーして貼る
  • そのままGitHubにあげると危ないのでdot.envを用意する
  • dbの設定
  • Google認証の設定
  • exportする
firebase.ts
// dbの設定
import { getFirestore } from "firebase/firestore/lite";
// Google認証の設定
import { getAuth, GoogleAuthProvider } from "firebase/auth";

......

// dbの設定
const db = getFirestore(app);
// Google認証の設定
const auth = getAuth(app);
const provider = new GoogleAuthProvider();
// exportする
export { db, auth, provider };
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?