I was working on a project which has an admin side, an admin could add another admins, and when an admin A add an admin B it automatically signin the admin B, so after many researches I found that firebase doesn't provide any way to prevent or disable this behavior.
So I wanted to find the best solutions for a perfect user interaction, as we say features comes to fix bugs, So here is my alternative solution to hide this 'bug' :
Frontend :
<TextField
fullWidth
label="Email"
type="email"
onChange={(email)=>{setEmail(email.target.value)}}
/>
<TextField
fullWidth
label="Password"
type="password"
onChange={(pass)=>{setPassword(email.target.value)}}
/>
<Button
onClick={createNewAdmin}
/>
<Dialog open={showDialog}>
<DialogContent>
<DialogContentText>
Tap your password !
</DialogContentText>
<TextField
label="Password"
type="password"
onClick={(pass)=>setReAuthPass(pass.target.value)}}
/>
</DialogContent>
<DialogActions>
<Button onClick={signAdminBack}>
Confirm
</Button>
</DialogActions>
</Dialog>
State :
const[email, setEmail] = React.useState('');
const[password, setPassword] = React.useState('');
const[oldEmail, setOldEmail] = React.useState('');
const[reAuthPass, setReAuthPass] = React.useState('');
const[showDialog, setDialog]=React.useState(false);
Functions :
const createNewAdmin=()=>{
const auth = getAuth();
//saving the current admin email
setOldEmail(auth.currentUser.email);
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
//opening the dialog
setDialog(true);
}).catch((error)=>{console.log(error);});
}
const signAdminBack=()=>{
const auth=getAuth();
signInWithEmailAndPassword(auth, oldEmail, reAuthPass).then((userCredential)=>{
//admin A brought back
//closing the dialog
}).catch((err)=>{
console.log(err);
});
}