How to use the kitsu/config/api.setToken function in kitsu

To help you get started, we’ve selected a few kitsu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hummingbird-me / kitsu-mobile / src / screens / Sidebar / Library / ImportDetail.js View on Github external
onImportButtonPressed = async () => {
    const { accessToken, currentUser, navigation } = this.props;
    const item = navigation.state.params.item;
    setToken(accessToken);
    const kind = item.title === 'MyAnimeList' ? 'my-anime-list' : 'anilist';
    this.setState({ loading: true });
    try {
      const res = await Kitsu.create('listImports', {
        user: { id: currentUser.id },
        inputText: this.state.username,
        strategy: 'greater',
        kind,
      });
      this.setState({
        showModal: true,
        loading: false,
        errMessage: res.errorMessage,
      });
    } catch (e) {
      // TODO: we may have crashes here.
github hummingbird-me / kitsu-mobile / src / screens / Onboarding / common / RateScreen / screen.js View on Github external
removeRating = async () => {
    const { currentIndex, topMedia } = this.state;
    const { accessToken, userId, type } = this.props;
    const id = topMedia[currentIndex].id;
    const libraryEntryId = topMedia[currentIndex].libraryEntryId;
    setToken(accessToken);

    let updatedTopMedia = topMedia.slice();
    updatedTopMedia[currentIndex].isRating = true;
    this.setState({
      topMedia: updatedTopMedia,
    });

    try {
      let response = null;
      // patch the previous rating
      response = await Kitsu.update('libraryEntries', {
        ratingTwenty: null,
        id: libraryEntryId,
        [type]: {
          id,
          type,
github hummingbird-me / kitsu-mobile / src / screens / Sidebar / SuggestFeatures.js View on Github external
getCannySsoKey = async () => {
    const { accessToken, currentUser } = this.props;
    setToken(accessToken);
    this.setState({ loading: true });
    try {
      // execute request. > will continue later after fixing pr review stuff.
    } catch (e) {
      // catch.
    }
  };
github hummingbird-me / kitsu-mobile / src / screens / Onboarding / Kitsu / ImportDetail.js View on Github external
onImportButtonPressed = async () => {
    const { accessToken, currentUser, item } = this.props;
    setToken(accessToken);
    const kind = item.title === 'MyAnimeList' ? 'my-anime-list' : 'anilist';
    this.setState({ loading: true, errMessage: null });
    try {
      const res = await Kitsu.create('listImports', {
        user: { id: currentUser.id },
        inputText: this.state.username,
        strategy: 'greater',
        kind,
      });
      this.setState({
        showModal: true,
        loading: false,
        errMessage: res.errorMessage,
      });
    } catch (e) {
      // TODO: we may have crashes here.
github hummingbird-me / kitsu-mobile / src / screens / Onboarding / common / FavoritesScreen.js View on Github external
onFaveCategory = async (id, index) => {
    const { id: userId } = this.props.currentUser;
    if (id) {
      setToken(this.props.accessToken);
      try {
        const res = await Kitsu.create('categoryFavorites', {
          category: {
            id,
          },
          user: {
            id: userId,
          },
        });
        const categories = this.props.favoriteCategories.slice();
        categories[index].favoritesId = res.id;
        return categories;
      } catch (e) {
        console.log(e);
      }
    } else {
github hummingbird-me / kitsu-mobile / src / store / user / actions.js View on Github external
export const disconnectFBUser = () => async (dispatch, getState) => {
  dispatch({ type: types.DISCONNECT_FBUSER });
  const token = getState().auth.tokens.access_token;
  const currentUser = getState().user.currentUser;
  setToken(token);
  try {
    await Kitsu.update('users', { id: currentUser.id, facebookId: null });
    dispatch({ type: types.DISCONNECT_FBUSER_SUCCESS });
    LoginManager.logOut();
  } catch (e) {
    dispatch({ type: types.DISCONNECT_FBUSER_FAIL, payload: 'Failed to disconnect fb user' });
    console.log(e);
  }
};
github hummingbird-me / kitsu-mobile / src / screens / Sidebar / PrivacySettings.js View on Github external
onSavePrivacySettings = async () => {
    const { shareToGlobal } = this.state;
    const { accessToken, currentUser } = this.props;
    setToken(accessToken);
    this.setState({ loading: true });
    try {
      await Kitsu.update('users', { id: currentUser.id, shareToGlobal });
      this.setState({
        shareToGlobal,
        loading: false,
      });
    } catch (e) {
      this.setState({
        error: 'Failed to set privacy settings',
        loading: false,
      });
    }
  };
github hummingbird-me / kitsu-mobile / src / store / onboarding / actions.js View on Github external
export const completeOnboarding = () => async (dispatch, getState) => {
  dispatch({ type: types.COMPLETE_ONBOARDING });
  const { user, auth } = getState();
  const { id } = user.currentUser;
  const token = auth.tokens.access_token;
  setToken(token);
  try {
    await Kitsu.update('users', { id, status: 'registered' });
    dispatch({ type: types.COMPLETE_ONBOARDING_SUCCESS });
    NavigationActions.showMainApp();
  } catch (e) {
    dispatch({ type: types.COMPLETE_ONBOARDING_FAIL, payload: e });
  }
};
github hummingbird-me / kitsu-mobile / src / screens / Sidebar / Blocking.js View on Github external
onUnblockUser = async (user) => {
    const { blocks } = this.state;
    const { id } = user;
    setToken(this.props.accessToken);
    this.setState({ loading: true });
    try {
      await Kitsu.destroy('blocks', id);
      this.setState({
        blocks: blocks.filter(v => v.id !== id),
        loading: false,
      });
    } catch (e) {
      this.onError(e);
    }
  };
github hummingbird-me / kitsu-mobile / src / screens / Sidebar / Library / ExportLibrary.js View on Github external
onDisconnectButtonPressed = async () => {
    const { accessToken } = this.props;
    const { linkedAccount } = this.state;
    setToken(accessToken);
    this.setState({ loading: true });
    try {
      await Kitsu.destroy('linkedAccounts', linkedAccount.id);
      this.setState({
        hasAccount: false,
        loading: false,
      });
    } catch (e) {
      this.setState({
        error: e,
        loading: false,
      });
    }
  }