Skip to content

useOAuth

Handles OAuth-based authentication and linking (Google, Facebook, Twitter).

Use cases:
  • Sign in users with OAuth providers.
  • Link OAuth accounts to an existing user.
Returns:
  • initOAuth and linkOauth: Functions for OAuth flows.
  • Status flags: isLoading, isError, isSuccess.
import { useOAuth } from "@openfort/react"
 
function SampleComponent() {
  const {
    initOAuth, // Initialize OAuth flow.
    linkOauth, // Link OAuth to an existing user.
    storeCredentials,
    isLoading, // Indicates if the hook is currently loading.
    isError, // Indicates if the hook has encountered an error.
    isSuccess, // Indicates if the hook has successfully completed.
    error, // The error object if an error occurred, otherwise null.
  } = useOAuth({
    redirectTo,
    throwOnError, // Whether to throw errors.
    onSuccess, // Callback function to execute on success.
    onError, // Callback function to execute on error.
    onSettled, // Callback function to execute when the operation is settled (either success or error).
  })
  // ...
}