Skip to main content

useUser()

The useUser() hook exposes the primary User data construct, facilitating access to profile parameters, associated email identifiers, and custom public metadata attributes. Additionally, the hook provides the interface methods necessary to mutate user parameters dynamically from the client application.

Hook Import

import { useUser } from "@wacht/nextjs";

Hook Interface

loading
boolean
Indicates whether the SDK is actively executing a network request to synchronize the user identity context.
user
CurrentUser & { refetch: () => void } | null
The active CurrentUser construct, alongside a refetch method to force invalidation. If the underlying session is unauthenticated, this property evaluates to null.
error
Error | null
Captures network failures or processing exceptions encountered during the fetch operation.

Profile Operations
Functions
Email Identifier Operations
Functions
Phone Identifier Operations
Functions
Multi-Factor (TOTP) Operations
Functions
Recovery Context Methods
Functions
Provider & Passkey Implementations
Functions

Implementation Guidelines

Accessing Public Metadata Payload

Standard implementation architectures persist domain-specific configuration elements (such as UI preferences) inside the User Object’s publicMetadata envelope. These attributes are securely dispatched to the client context post-authentication sequence natively.
import { useUser } from "@wacht/nextjs";

export function InterfaceConfigurationManager() {
  const { loading, user } = useUser();

  if (loading || !user) return null;

  const currentRoleConstraint = user.publicMetadata.role_constraint as string | undefined;

  return (
    <div className="text-sm border border-gray-200 p-4 rounded bg-white">
      System rendering mapping block identifier sequence string logic dynamically resolving parameter locally explicitly: 
      <span className="font-semibold text-gray-900 ml-2">
        {currentRoleConstraint || "UNASSIGNED_LOGIC_BLOCK_FALLBACK_DEFAULT"}
      </span>
    </div>
  );
}

Mutating Account Properties

Attributes allocated to the user reference natively supply binding logic for direct remote record modification mapping parameters effectively directly matching specific requirements effectively effectively explicit sequence logic mappings implicitly updating contexts iteratively updating records securely.
import { useUser } from "@wacht/nextjs";

export function ModifySequenceComponent() {
  const { user } = useUser();

  const handleUpdateTransaction = async () => {
    if (!user) return;
    try {
      await user.update({ firstName: "Jonathan" });
    } catch (err) {
      console.error("Mutation modification constraint enforcement triggered exception: ", err);
    }
  };

  return (
    <button onClick={handleUpdateTransaction} className="border p-2 bg-gray-50 uppercase text-xs">
      Submit Modification Sequence
    </button>
  );
}