How to use the @rematch/core.dispatch.auth function in @rematch/core

To help you get started, we’ve selected a few @rematch/core 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 EvanBacon / pro-chat / client / src / rematch / auth.js View on Github external
async function upgradeAccountWithAuthAsync({ token, provider }) {
  if (!token || !provider) {
    throw new Error('upgradeAccountWithAuth: Invalid token or provider');
  }

  try {
    const user = await upgradeWithTokenAndProvider({ token, provider });
    console.log('upgradeAccountWithToken: Upgraded Successful');
    dispatch.auth.authorized(user);
  } catch ({ message, code, ...error }) {
    if (code === 'auth/credential-already-in-use') {
      // Delete current account while signed in
      // TODO: This wont work
      const { uid } = Fire.shared;
      if (uid) {
        console.log('Should delete:', uid);
        await deleteUserAsync(uid);
        console.log('All deleted');
      } else {
        console.log('??? do something:', uid);
      }
      await loginToFirebaseWithAuthAsync({ token, provider });
    } else {
      // If the account is already linked this error will be thrown
      console.log('Error: upgradeAccountWithToken', message);
github EvanBacon / pro-chat / client / src / rematch / auth.js View on Github external
async function getFacebookTokenAsync() {
  let auth;
  try {
    auth = await Facebook.logInWithReadPermissionsAsync(
      Constants.manifest.facebookAppId,
      Settings.facebookLoginProps,
    );
  } catch ({ message }) {
    Alert.alert('Facebook Login Error:', message);
  }
  if (auth) {
    const { type, expires, token } = auth;
    if (type === FacebookLoginTypes.Success) {
      dispatch.auth.set({ expires, token });
    } else if (type === FacebookLoginTypes.Cancel) {
      // do nothing, user cancelled
    } else {
      // unknown type, this should never happen
      Alert.alert('Failed to authenticate', type);
    }
    return token;
  }
  return null;
}
github EvanBacon / pro-chat / client / src / rematch / auth.js View on Github external
async function loginToFirebaseWithAuthAsync({ token, provider }) {
  if (!token || !provider) {
    throw new Error('upgradeAccountWithAuth: Invalid token or provider');
  }

  try {
    const user = await signInWithTokenAndProvider(token, provider);
    dispatch.auth.authorized(user);
  } catch ({ message }) {
    console.log('Error: loginToFirebase');
    Alert.alert(message);
  }
}
github EvanBacon / pro-chat / client / src / screens / SettingsScreen.js View on Github external
      logout: () => dispatch.auth.logoutAsync(),
      delete: () => {},