Skip to content

Commit c1fc96d

Browse files
Bilal-Abdeenmikehardy
authored andcommitted
docs(auth): added onAuthStateChanged to the signInWithPhoneNumber Example
related to #530
1 parent 257d19c commit c1fc96d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

docs/auth/phone-auth.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,24 @@ function PhoneSignIn() {
6262
// If null, no SMS has been sent
6363
const [confirm, setConfirm] = useState(null);
6464

65+
// verification code (OTP - One-Time-Passcode)
6566
const [code, setCode] = useState('');
6667

68+
// Handle login
69+
function onAuthStateChanged(user) {
70+
if (user) {
71+
// Some Android devices can automatically process the verification code (OTP) message, and the user would NOT need to enter the code.
72+
// Actually, if he/she tries to enter it, he/she will get an error message because the code was already used in the background.
73+
// In this function, make sure you hide the component(s) for entering the code and/or navigate away from this screen.
74+
// It is also recommended to display a message to the user informing him/her that he/she has successfully logged in.
75+
}
76+
}
77+
78+
useEffect(() => {
79+
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
80+
return subscriber; // unsubscribe on unmount
81+
}, []);
82+
6783
// Handle the button press
6884
async function signInWithPhoneNumber(phoneNumber) {
6985
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);

0 commit comments

Comments
 (0)