0Pricing
Firebase Auth & Realtime Database Apps · 강의

사용자 데이터에 대한 역할 기반 접근 제어

Firebase Auth 역할과 Realtime Database 규칙을 결합하여 관리자, 멤버, 게스트에게 공유 데이터와 개인 데이터에 대한 서로 다른 접근 수준을 부여합니다.

사용자 데이터에 대한 역할 기반 접근 제어은(는) CoddyKit의 무료 Firebase Auth & Realtime Database Apps 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Firebase Auth & Realtime Database Apps 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Firebase Auth & Realtime Database Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Beyond Owner-Only Access

So far each user reads and writes their own data. Real apps need roles: an admin who moderates content, members who collaborate, and guests with read-only access.

Role-based access control (RBAC) layers permissions on top of authentication.

Where Roles Live

You can store a user's role in two places:

  • A roles node in the database, read inside rules
  • A custom claim on the auth token (set server-side)

Custom claims are faster to check; database roles are easier to change at runtime.

Roles in the Database

A simple model maps each uid to a role string. This data itself must be locked down so users cannot promote themselves.

{
  "roles": {
    "uid_alice": "admin",
    "uid_bob": "member"
  }
}

Checking a Database Role in Rules

Rules can read other parts of the database with root. Here only admins may write to a shared config node.

{
  "rules": {
    "config": {
      ".write": "root.child('roles').child(auth.uid).val() === 'admin'"
    }
  }
}

Custom Claims for Roles

With the Admin SDK you can attach a role to the token itself. This is checked without an extra database read.

await admin.auth().setCustomUserClaims(uid, { role: 'admin' });

Checking Claims in Rules

Custom claims appear under auth.token. The rule becomes simpler and avoids a root lookup.

{
  "rules": {
    "config": {
      ".write": "auth.token.role === 'admin'"
    }
  }
}

Reading the Claim Client-Side

The client can read its own claims to adjust the UI, for example showing an admin panel only to admins.

import { getAuth, getIdTokenResult } from 'firebase/auth';

const res = await getIdTokenResult(getAuth().currentUser);
if (res.claims.role === 'admin') showAdminPanel();

Tiered Read Access

Different roles can have different read scopes. Members read shared docs; guests read only public ones.

{
  "rules": {
    "shared": {
      ".read": "auth.token.role === 'member' || auth.token.role === 'admin'"
    }
  }
}

Protecting the Role Data Itself

Critically, users must not be able to edit their own role. Make the roles node writable only by admins (or only server-side), or self-escalation defeats the whole system.

{
  "rules": {
    "roles": {
      ".write": "auth.token.role === 'admin'"
    }
  }
}

Claim Propagation Delay

After you change a custom claim, the user's existing token still has the old value until it refreshes (about an hour, or on forced refresh). Call getIdToken(true) client-side to pick up new roles immediately.

await getAuth().currentUser.getIdToken(true);

Choosing an Approach

Use custom claims for stable, security-critical roles, and database roles when permissions change often or need to be queried. Many apps combine both.

Quick Check

Test your understanding of role-based access.

Recap

You can now grant tiered access by role.

  • Store roles in the database or as custom claims
  • Check database roles via root, claims via auth.token
  • Give roles different read/write scopes
  • Lock down the role data so users cannot self-promote
  • Refresh tokens to pick up new claims promptly

자주 묻는 질문

“사용자 데이터에 대한 역할 기반 접근 제어” 강의는 무료인가요?

네 — “사용자 데이터에 대한 역할 기반 접근 제어” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Firebase Auth & Realtime Database Apps 강의 전체를 잠금 해제할 수 있습니다. Firebase Auth & Realtime Database Apps 강의에는 총 4개의 강의가 포함되어 있습니다.

“사용자 데이터에 대한 역할 기반 접근 제어”에서 뭘 배우나요?

Firebase Auth 역할과 Realtime Database 규칙을 결합하여 관리자, 멤버, 게스트에게 공유 데이터와 개인 데이터에 대한 서로 다른 접근 수준을 부여합니다. 브라우저에서 직접 실행하는 실습 코드로 Firebase Auth & Realtime Database Apps을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Firebase Auth & Realtime Database Apps을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Firebase Auth & Realtime Database Apps은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“사용자 데이터에 대한 역할 기반 접근 제어” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Firebase Auth & Realtime Database Apps 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Firebase Auth & Realtime Database Apps 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 사용자 데이터를 인증 정보에 연결하기
  2. 실시간 사용자 프로필
  3. 협업 데이터 편집
  4. 사용자 데이터에 대한 역할 기반 접근 제어
← Firebase Auth & Realtime Database Apps(으)로 돌아가기