Options
All
  • Public
  • Public/Protected
  • All
Menu

@crossid/crossid-react

Index

Functions

Const AuthProvider

  • AuthProvider<T>(props: AuthProps): Element
  • Type parameters

    • T: IDToken

    Parameters

    • props: AuthProps

    Returns Element

Const useAuth

  • useAuth<T>(): AuthContextType<T>
  • useAuth is a hook to handle authentication.

    T can optionally be set to your custom IDToken type.

    const {
      // true if hook is currently loading, can be used to defer loading page with a spinner.
      loading: boolean
      // An error that has occured during authentication phases.
      error?: Error
      // The ID token if the authenticated user.
      idToken?: T
      // a method to start login by redirecting browser to crossid authorization provider.
      loginWithRedirect,
      // a method to start logout by redirecting browser to crossid authorization provider.
      logoutWithRedirect,
      // returns a promise which eventually returns the access token of the authenticated user.
      getAccessToken
    } = useAuth()
    

    Type parameters

    • T: IDToken = IDToken

    Returns AuthContextType<T>

withAuth

  • withAuth<T>(WrappedComponent: React.ComponentType<T>, opts?: AuthRequiredOpts): (props: T) => Element
  • a high order component that renders children only if user is authenticated. anonymous visitors will be redirected to the login page.

    wrap your private routes with this high order component.

    Type parameters

    • T

    Parameters

    • WrappedComponent: React.ComponentType<T>
    • opts: AuthRequiredOpts = {}

    Returns (props: T) => Element

      • (props: T): Element
      • Parameters

        • props: T

        Returns Element