Skip to content

How to prevent queries by roles #437

Answered by eddyhdzg
eddyhdzg asked this question in Q&A
Discussion options

You must be logged in to vote

I solved it by using useSigninCheck as in #368 (comment) and a Wrapper similar to the AuthWrapper in the example folder.

A Simple hook to check if user is an admin

import { useSigninCheck } from "reactfire";
import { UserRole } from "types";
import { adminArray } from "constant";

export default function useIsAdmin() {
  const { status, data: signInCheckResult } = useSigninCheck({
    validateCustomClaims: (userClaims) => {
      return {
        hasRequiredClaims: adminArray.has(userClaims.role as UserRole),
        errors: {},
      };
    },
  });

  return { status, signInCheckResult };
}

AdminWrapper

import { CenterLoader, MessagePaper } from "components";
import { useIsAdmin } from "…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jhuleatt
Comment options

@jhuleatt
Comment options

@eddyhdzg
Comment options

Answer selected by jhuleatt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants