Skip to main content
This hook requires the user to be authenticated.

Overview

useOAuthIdentities fetches the list of OAuth identities linked to the current user’s account and provides a function to unlink them. Use it to build a connected accounts settings page.

Usage Example

import { useEffect } from "react";
import { useOAuthIdentities } from "@replyke/react-js";

function LinkedIdentities() {
  const { identities, fetchIdentities, unlinkIdentity, isLoading, error } =
    useOAuthIdentities();

  useEffect(() => {
    fetchIdentities();
  }, []);

  if (isLoading) return <p>Loading...</p>;
  if (error) return <p>Error: {error}</p>;

  return (
    <ul>
      {identities.map((identity) => (
        <li key={identity.id}>
          {identity.provider}{identity.email ?? identity.name ?? "Unknown"}
          <button onClick={() => unlinkIdentity({ identityId: identity.id })}>Unlink</button>
        </li>
      ))}
    </ul>
  );
}

Returns

identities
OAuthIdentity[]
Array of OAuth identities linked to the current user. Initially empty; call fetchIdentities to populate.
fetchIdentities
function
Async function that fetches the identities list from the server and updates local state. Returns void.
Async function that unlinks a specific identity. Accepts { identityId: string }. On success, removes the identity from the local identities array. Fails if it would be the last identity and the user has no password set.
isLoading
boolean
true while a fetch or unlink request is in progress.
error
string | null
Error message from the most recent failed operation, or null if no error.

OAuthIdentity Type

PropertyTypeDescription
idstringUnique identity ID (UUID)
providerstringOAuth provider name (e.g., "google", "github")
providerAccountIdstringThe user’s ID at the provider
emailstring | nullEmail returned by the provider
namestring | nullName returned by the provider
avatarstring | nullAvatar URL returned by the provider
isVerifiedbooleanWhether the provider marked the email as verified
createdAtstringISO timestamp of when the identity was linked

See Also