Skip to content

Commit

Permalink
Sett anonymous user to be delete when login in
Browse files Browse the repository at this point in the history
  • Loading branch information
erikswed committed Nov 13, 2020
1 parent 6342df3 commit e278c13
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Firestore-rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{Id=**} {
// users:
// - Authenticated user can read
// - Authenticated user can create
// - updates
//
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "greta-thunberg-fff",
"version": "1.0.9",
"version": "1.1.0",
"private": true,
"main": "index.js",
"module": "dist/index.js",
Expand Down
11 changes: 11 additions & 0 deletions src/components/profile/LinkAccounts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class LoginManagementBase extends Component {
.then(this.fetchSignInMethods)
.catch(error => {
if (error.code === 'auth/credential-already-in-use') {
const anonUser = firebase.auth.currentUser;
firebase.auth
.signInWithCredential(error.credential)
.then(res => {
Expand All @@ -64,6 +65,16 @@ class LoginManagementBase extends Component {
firebase.doLogEvent(`signInWithCredential to Firestore for: ${res.credential.providerId}`);
}
changeUserRole();
// remove the anonUser TODO implications?
anonUser
.delete()
.then(() => {
firebase.doLogEvent(`Deleted anonUser when signing in`);
})
.catch(err => {
firebase.doLogEvent(`Error deleted anonUser when signing in: ${err}`);
firebase.doLogEvent(`Manually remove anon account: ${anonUser.uid}`);
});
})
.catch(err => {
this.setState(err.message);
Expand Down

0 comments on commit e278c13

Please sign in to comment.