sourcetip

클라이언트에 Firebase에서 원하는 데이터에 액세스할 수 있는 권한이 없습니다.

fileupload 2023. 2. 17. 21:33
반응형

클라이언트에 Firebase에서 원하는 데이터에 액세스할 수 있는 권한이 없습니다.

호출 중인 페이지가 있습니다.addCheckin()컨트롤러 내부에 있는 메서드.컨트롤러에서 다음과 같이 참조를 작성하려고 합니다.

var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");

$scope.whichuser그리고.$scope.whichmeeting$routeParams다른 경로에서 오는 길이에요.여기 제 체크인 컨트롤러가 있습니다.

myApp.controller("CheckinsController",
    ['$scope','$rootScope','$firebaseArray','$routeParams','$firebaseObject',
    function($scope,$rootScope,$firebaseArray,$routeParams,$firebaseObject){

        $scope.whichuser = $routeParams.uid;
        $scope.whichmeeting = $routeParams.mid;

        var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");

        $scope.addCheckin = function(){
            var checkinInfo = $firebaseArray(ref);
            var data={
                firstname:$scope.firstname,
                lastname:$scope.lastname,
                email:$scope.email,
                date:firebase.database.ServerValue.TIMESTAMP
            }

            checkinInfo.$add(data);
        }

}]);/*controller*/

두 가지 오류가 있습니다.

오류 1:

Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings: Client doesn't have permission to access the desired data.

오류 2:

Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings/-KT5tqMYKXsFssmcRLm6/checkins: Client doesn't have permission to access the desired data.

그리고 이게 내가 목표로 하는 거야

여기에 이미지 설명 입력

앱의 Firebase 콘솔로 이동

[ Database From Side Menu ]를 선택합니다.-- > 위의 탭에서 규칙 선택 -- > 규칙을 다음과 같이 업데이트합니다.

{
    "rules": {    
        ".read": true,
        ".write": true
    }
}

그것이 당신의 문제를 해결하기를 바랍니다. 감사합니다. :)

기본적으로 Firebase 프로젝트는 Firestore를 데이터베이스로 시작합니다.

이 문제는 응용 프로그램에서 "FireBase Realtime Database"를 사용하고 있으며 이에 대한 권한이 구성되지 않은 경우 발생할 수 있습니다.Firebase Realtime Database에 대한 읽기 및 쓰기 권한이 명시적으로 부여되어야 합니다.

이를 수행하려면 Firebase 콘솔에서 [Database]> [ Rules ]> [ Set ]의 드롭다운에서 [Firestore Beta]가 아닌 [Realtime Database]를 선택합니다.

{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
"rules": {
".read": true,
".write": true
}
}

도움이 되길 바라!

모든 답변에는 보안상의 문제가 포함되어 있습니다.예를 들어 잘못된 방법으로 사용하면 비용이 많이 들거나 데이터가 완전히 손실될 수 있습니다.

물론 이러한 규칙을 사용하려면 FireBase 인증 기능을 사용해야 하지만 익명성에 대한 쓰기 액세스를 막는 것이 기본입니다.다음 규칙은 보안을 유지하면서 모든 사용자에게 읽기 액세스를 제공합니다.

{
    "rules": {
        ".read": true,
        ".write": "auth.uid != null"
    }
}

이러한 답변 중 어느 것도 실시간 데이터베이스를 설정하는 가장 안전한 방법을 제공하지 않습니다.

  • 다른 사용자가 임의로 데이터베이스에 액세스하거나 데이터베이스에 쓰는 것을 원하지 않습니다.
  • 사용자가 인증되었더라도 다른 사용자의 데이터에 액세스하지 않도록 합니다.

이 규칙은 모든 경우에 대응해야 합니다.

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

아래 코드를 사용하여 파이어베이스에 등록하십시오.

Firebase.auth()
            .createUserWithEmailAndPassword(email, password)
            .then((data) => console.log(data))
            .catch(error => console.log(error))

아래 코드로 등록된 이메일과 비밀번호를 사용하여 본인 인증을 받습니다.

Firebase.auth()
           .signInWithEmailAndPassword(email, password)
           .then((data) => console.log(data))
           .catch(error => console.log(error))

실시간 데이터베이스에 다음 규칙을 사용하여

{
   "rules": {
    ".read": "auth != null",
    ".write": "auth != null"    
    }
}

그러면 실시간 데이터베이스에서 데이터에 자동으로 액세스할 수 있습니다.

var ref = firebase.database().ref("users");
ref.on("value", function(snapshot) {
 snapshot.forEach(function(childSnapshot) {
  var childData = childSnapshot.val();
  var id=childData.id;
  console.log(childData);
 });
});

로그아웃하는 동안 다음 명령을 추가하여 앱에서 로그아웃합니다.

Firebase.auth().signOut()

인증된 모든 사용자에게 액세스 권한을 부여하려면 Firebase Web 콘솔에서 데이터베이스 규칙 탭으로 이동하여 다음 규칙을 복사/붙여넣습니다.

{
   "rules": {
    ".read": "auth != null",
    ".write": "auth != null"    
    }
}

/users/{uid} 루트는 쓸 수 있지만 읽을 수는 없는 것 같습니다./users를 /userx로 변경했더니 바로 작동하기 시작했습니다.

이게 도움이 되었으면 좋겠어요.

{
    ".read": true,
    ".write": "auth !== null && root.child('users').child(auth.uid).child('meetings').val() ===  true"
}

뺄 수 . && root.child('users').child(auth.uid).child('meetings').val() === true"

결과는 똑같습니다.

허가할 때까지의 시간을 다음과 같이 지정할 수도 있습니다.

[ Database From Side Menu ]를 선택합니다.-- > 위의 탭에서 규칙 선택 -- > 규칙을 다음과 같이 업데이트합니다.

{
  "rules": {
    ".read": "now < 1672384350000",  // 2022-12-30
    ".write": "now < 1672384350000",  // 2022-12-30
  }
}

만 the the the the the the the the ?Error: permission_denied올바른 읽기 권한을 허용하고 Firebase npm 패키지로 데이터를 가져오는 경우 Cloud Firestore가 아닌 Realtime Database에서 읽으려고 하기 때문일 수 있습니다.

빠르고 쉬운 설정을 위해 react-redux-firebase npm 패키지를 사용하고 있었습니다.기본적으로는 실시간 데이터베이스를 사용합니다.Cloud Firestore를 사용하는 경우 설정에 다음과 같이 기술해야 합니다.useFirestoreForProfiletrue.

import { ReactReduxFirebaseProvider } from 'react-redux-firebase';

const store = configureStore();
const rrfProps = {
  firebase,
  config: { 
    userProfile: 'users', 
    useFirestoreForProfile: true  // Firestore for Profile instead of Realtime DB
  },
  dispatch: store.dispatch,
  createFirestoreInstance,
};

호에서 설명한 바와 같이 실시간 데이터베이스를 지원하지만 Cloud Firestore를 지원하지 않는 Flamelink와 같은 Firebase용 다른 패키지와 유사한 문제가 있을 수 있습니다.

언급URL : https://stackoverflow.com/questions/39850118/client-doesnt-have-permission-to-access-the-desired-data-in-firebase

반응형