Skip to content

Dependent hooks #12

@nhagen

Description

@nhagen

Seems like a common flow I see for defining admin users is to have an admin collection, and then you can check the authenticated user against that collection to make a determination.

Since hooks can't show conditionally, the syntax for doing this seems to be along the lines of:

const { initializing, user } = useAuthState(auth);
const { loading, error, value } = useDocument(db.doc(`admins/${ user && user.email }`));
...
const isAdmin = !!value.exists;

In this case, we begin by querying via useDocument for a document we know won't work (admins/), but it of course works fine when user.email is available.

Is there a better way of doing this with hooks and firebase?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions