Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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;
}
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);
}
}
logout: () => dispatch.auth.logoutAsync(),
delete: () => {},
onPress={() => {
dispatch.auth.login();
}}
>