Skip to content

Commit

Permalink
Adding deleteAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteLecat committed Apr 3, 2024
1 parent 37cc3a0 commit 378d99b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,24 @@ export const onUserCreated = functions.region("europe-west1").auth.user().onCrea
photoURL: user.photoURL,
createdAt: admin.firestore.FieldValue.serverTimestamp(),
});
});


//Cloud function to allow a user to delete their account
export const deleteAccount = functions.region("europe-west1").https.onCall(async (data, context) => {
const uid = context.auth?.uid;
if (uid == null) {
throw new functions.https.HttpsError('unauthenticated', 'You must be logged in to delete your account');
}

//delete the user's document in firestore
const userRef = db.collection('users').doc(uid);
await userRef.delete();

//delete the user's account
await admin.auth().deleteUser(uid);

return {
success: true
};
});

0 comments on commit 378d99b

Please sign in to comment.