Get it on Google Play


Wm뮤 :: 파이어 베이스 DB 보안

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2021. 10. 16. 20:21 FireBase

 

 

 

참고한곳

https://firebase.google.com/docs/database/security?hl=ko 

 

Firebase 실시간 데이터베이스 규칙 이해  |  Firebase Documentation

Join us for Firebase Summit on November 10, 2021. Tune in to learn how Firebase can help you accelerate app development, release with confidence, and scale with ease. Register 의견 보내기 Firebase 실시간 데이터베이스 규칙 이해 Firebase

firebase.google.com

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


using Firebase;
using Firebase.Database;
public class FireBaseDataBase : MonoBehaviour
{
    DatabaseReference reference ;
    public class User
    {
        public string username;
        public string email;

        public User(string username, string email)
        {
            this.username = username;
            this.email = email;
        }
    }
    public void WriteNewUser()
    {

        var auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

        WriteNewUser(auth.CurrentUser.UserId, "test", "test@mail");//작동함
        WriteNewUser(auth.CurrentUser.UserId, "test2", "test2@mail");//작동함
        WriteNewUser("ABC"+(auth.CurrentUser.UserId).Substring("ABC".Length), "test2", "test2@mail");//작동함!!

    }
    private void WriteNewUser(string userId, string name, string email)
    {
        User user = new User(name, email);
        string json = JsonUtility.ToJson(user);

        reference.Child("users").Child(userId).SetRawJsonValueAsync(json);
    }
    // Start is called before the first frame update
    void Start()
    {
        reference = FirebaseDatabase.DefaultInstance.RootReference;

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 

 

상기와 같은 코드가 있다

 

 

이걸 그냥 쑤셔넣게 되면

 

 

 

 

 

 

 

자기 계정이 아닌데도 마음대로 값을 쓰고 수정해댄다

당연하다 저 계층값이 유저 ID인지 지역별 구분인지 이름인지 컴퓨터는 알수 없기 때문

따라서 저 계층은 uid와 동일할때만 값을 추가할수 있게 해달라고 할 것이다

 

 

 

 

 

 

 

열어보면 이렇게 되어있을것이다

11월 2일까지만 쓸 수 있댄다.

규칙을 바꿔주자

 

 

 

 

 

{
  "rules": 
  {
    "users": 
    {
      "$uid": 
      {
        ".write": "$uid === auth.uid",
        ".read": "$uid === auth.uid"
      }
    }
  }
}

uid가 동일해야만 읽고 쓸 수 있게 수정했다

이제 DB에 들어와서 아무나 난동부릴 수 없게됐다 Good

 

테스트 했던 유저값들은 지워주자

 

기본적으로 .write 규칙이 미정의된 부분은 쓰기 불가능이니 rules에 대한 룰은 지정 안 해주어도 될것이다

posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입