Skip to content

Commit

Permalink
Added signout method
Browse files Browse the repository at this point in the history
  • Loading branch information
cdnicoll committed Mar 14, 2019
1 parent 2d451b6 commit 916c62d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 58 deletions.
12 changes: 6 additions & 6 deletions .expo/packager-info.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"devToolsPort": 19002,
"expoServerPort": 19000,
"packagerPort": 19001,
"packagerPid": 3555,
"expoServerNgrokUrl": "https://tz-viz.cdnicoll.react-native-data-storage.exp.direct",
"packagerNgrokUrl": "https://packager.tz-viz.cdnicoll.react-native-data-storage.exp.direct",
"ngrokPid": 3583
"expoServerPort": null,
"packagerPort": null,
"packagerPid": null,
"expoServerNgrokUrl": null,
"packagerNgrokUrl": null,
"ngrokPid": null
}
6 changes: 5 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ Todo:
✔ Login Form @created(03-08-19 15:44) @done(03-12-19 16:33)
✔ Button to update account @created(03-08-19 15:44) @done(03-12-19 16:33)
☐ Button to sign out @created(03-08-19 15:44)
~ If account is a perminant account they should not be able to sign in as anonymous, or they can but shoudn't see data from linked account
~ Only show if the account is linked
~ Remove all data that is within employees
~ treated as a new anonymous user
☐ Sign in get employees @created(03-14-19 14:30)
~ If there is already employee data, grab it
✔ Convert anonymous account to a perminant account @created(03-07-19 12:30) @done(03-13-19 15:08)
~ https://firebase.google.com/docs/auth/web/anonymous-auth
✔ Link account @created(03-12-19 16:00) @done(03-12-19 20:54)
Expand Down
5 changes: 3 additions & 2 deletions src/components/screens/AccountScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class AccountScreen extends React.Component {

unlinkEmailPass = async () => {
try {
await User.unlinkAccount();
await User.loginAnonymous();
await User.signout();
//await User.unlinkAccount();
//await User.loginAnonymous();
} catch(err) {
console.log(err);
}
Expand Down
110 changes: 61 additions & 49 deletions src/db/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,48 @@ export default {

// Get reference to the currently signed-in user
const prevUser = firebase.auth().currentUser;
return auth
.signInAndRetrieveDataWithCredential(credential)
.then(function(userCredential) {
const user = userCredential.user;
var currentUser = user;
// Merge prevUser and currentUser data stored in Firebase.
// Note: How you handle this is specific to your application
return new Promise((resolve, reject) => {
auth
.signInAndRetrieveDataWithCredential(credential)
.then(function(userCredential) {
const user = userCredential.user;
var currentUser = user;
// Merge prevUser and currentUser data stored in Firebase.
// Note: How you handle this is specific to your application

// inject something in?
console.log(
'TODO: Merge prevUser and currentUser data stored in Firebase.',
);
// inject something in?
console.log(
'TODO: Merge prevUser and currentUser data stored in Firebase.',
);

// After data is migrated delete the duplicate user
return user
.delete()
.then(function() {
console.log('Link the OAuth Credential to original account');
// Link the OAuth Credential to original account
return prevUser.linkAndRetrieveDataWithCredential(credential);
})
.then(function() {
console.log('Sign in with the newly linked credential');
// Sign in with the newly linked credential
console.log('setting persistence');
auth
.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(function() {
console.log('persistance set');
return auth.signInAndRetrieveDataWithCredential(credential);
})
.catch(function(error) {
// Handle Persistance Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(error);
});
});
})
.catch(function(error) {
console.log('Sign In Error', error);
});
// After data is migrated delete the duplicate user
return user
.delete()
.then(function() {
console.log('Link the OAuth Credential to original account');
// Link the OAuth Credential to original account
return prevUser.linkAndRetrieveDataWithCredential(credential);
})
.then(function() {
console.log('Sign in with the newly linked credential');
// Sign in with the newly linked credential
console.log('setting persistence');
auth
.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(function() {
console.log('persistance set');
return auth.signInAndRetrieveDataWithCredential(credential);
})
.catch(function(error) {
reject(error);
});
});
})
.catch(function(error) {
reject(error);
});
resolve(true)
});
},

/**
Expand All @@ -87,18 +87,30 @@ export default {
const { currentUser } = firebase.auth();
console.log(currentUser.providerData[0].providerId);
return new Promise((resolve, reject) => {
currentUser
.unlink(currentUser.providerData[0].providerId)
.then(function() {
console.log("unlinked users account");
resolve(true)
})
.catch(function(error) {
reject(error)
})
currentUser
.unlink(currentUser.providerData[0].providerId)
.then(function() {
console.log('unlinked users account');
resolve(true);
})
.catch(function(error) {
reject(error);
});
});
},

/**
* Signs account out
*/
signout: async () => {
try {
await firebase.auth().signOut();
// signed out
} catch (e){
throw e;
}
},

/**
* Checks if the user is already logged int
* @return {object} current user
Expand Down

0 comments on commit 916c62d

Please sign in to comment.