soundcloud-api-ts-next
    Preparing search index...

    Function useSCAuth

    • Access SoundCloud OAuth authentication state and actions.

      Provides the current user, login/logout functions, and a callback handler for completing the OAuth flow.

      Returns {
          isAuthenticated: boolean;
          loading: boolean;
          login: () => void;
          logout: () => Promise<void>;
          user: SoundCloudUser | null;
          handleCallback(code: string, state: string): Promise<any>;
      }

      An object with user, isAuthenticated, loading, login, logout, and handleCallback.

      • isAuthenticated: boolean

        Whether the user is fully authenticated.

      • loading: boolean

        true while user profile is loading after token exchange.

      • login: () => void

        Initiate OAuth login — redirects to SoundCloud.

      • logout: () => Promise<void>

        Log out and clear all auth state.

      • user: SoundCloudUser | null

        The authenticated user profile, or null.

      • handleCallback: function
        • Handle OAuth callback — exchange authorization code for tokens.

          Parameters

          • code: string

            The authorization code from the callback URL.

          • state: string

            The state parameter from the callback URL.

          Returns Promise<any>

          The token response from SoundCloud.

      import { useSCAuth } from "soundcloud-api-ts-next";

      function AuthButton() {
      const { isAuthenticated, user, login, logout } = useSCAuth();
      if (isAuthenticated) return <button onClick={logout}>Logout {user?.username}</button>;
      return <button onClick={login}>Login with SoundCloud</button>;
      }