import { useApi } from './api.mjs';
import { ExtensionHasNoFieldError } from './errors.mjs';

/**
 * Provides access to session tokens, which can be used to verify token claims on your app's server.
 */
function useSessionToken() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('sessionToken' in api)) {
    throw new ExtensionHasNoFieldError('sessionToken', extensionTarget);
  }
  return api.sessionToken;
}

export { useSessionToken };
