Sanity Library Reference Docs
    Preparing search index...

    Interface AuthStoreBeta

    The interface used by the Studio that produces a SanityClient and CurrentUser that gets passed to the resulting Workspaces and Sources.

    NOTE: This interface is primarily for internal use. Refer to createAuthStore instead.

    interface AuthStore {
        handleCallbackUrl?: () => Promise<void>;
        LoginComponent?: ComponentType<LoginComponentProps>;
        logout?: () => void;
        state: Observable<AuthState>;
        token?: Observable<string>;
    }
    Index

    Properties

    handleCallbackUrl?: () => Promise<void>

    Custom auth stores can implement a function that is designated to run when the Studio loads (e.g. to trade a session ID for a token in cookie-less mode). Within the Studio, this is called within the AuthBoundary.

    LoginComponent?: ComponentType<LoginComponentProps>

    Custom auth stores are expected to implement a UI that initiates the user's authentication. For the typical case in createAuthStore, this means loading the providers and showing them as options to the user.

    logout?: () => void

    Custom auth stores can implement a function that runs when the user logs out. The implementation is expected to remove all credentials both locally and on the server.

    state: Observable<AuthState>

    Emits AuthStates. This should update when the user's auth state changes. E.g. After a login, a new AuthState could be emitted with a non-null currentUser and authenticated: true

    NOTE: all auth store implementations should emit on subscribe using something like shareReplay(1) to ensure all new subscribers get an AuthState value on subscribe

    token?: Observable<string>

    Emits auth tokens, or null if not configured to use them or they do not exist