Challenge - 5 Problems
Authentication Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Email Authentication UI Behavior
What will happen when the user taps the 'Login' button with empty email and password fields in this React Native component?
React Native
import React, { useState } from 'react'; import { View, TextInput, Button, Alert } from 'react-native'; export default function LoginScreen() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const handleLogin = () => { if (!email || !password) { Alert.alert('Error', 'Email and password are required'); } else { Alert.alert('Success', 'Logging in...'); } }; return ( <View> <TextInput placeholder='Email' value={email} onChangeText={setEmail} /> <TextInput placeholder='Password' value={password} onChangeText={setPassword} secureTextEntry /> <Button title='Login' onPress={handleLogin} /> </View> ); }
Attempts:
2 left
💡 Hint
Check the condition inside the handleLogin function that checks if email or password is empty.
✗ Incorrect
The handleLogin function checks if either email or password is empty. If so, it shows an alert with the message 'Email and password are required'. Since both fields are empty, option A is correct.
🧠 Conceptual
intermediate1:30remaining
Google Sign-In Token Usage
After a user successfully signs in with Google in a React Native app, what is the main purpose of the ID token received from Google?
Attempts:
2 left
💡 Hint
Think about why your app backend needs a token from Google.
✗ Incorrect
The ID token is a secure token that proves the user has authenticated with Google. Your backend server uses it to verify the user's identity safely. Displaying email or logging out are not the token's main purpose.
❓ lifecycle
advanced2:00remaining
Apple Sign-In Button Behavior on iOS
In a React Native app using Apple Sign-In, what happens if the user cancels the sign-in process after tapping the Apple Sign-In button?
Attempts:
2 left
💡 Hint
Consider how the Apple Sign-In API communicates cancellation.
✗ Incorrect
When the user cancels Apple Sign-In, the API returns an error indicating cancellation. The app should handle this gracefully. It does not retry automatically or crash if handled properly.
📝 Syntax
advanced2:30remaining
Correct Google Sign-In Hook Usage
Which option correctly uses the React Native Google Sign-In hook to get the user's email after sign-in?
React Native
import { useGoogleSignIn } from '@react-native-google-signin/google-signin'; function MyComponent() { const { signIn } = useGoogleSignIn(); const handleGoogleLogin = async () => { try { const userInfo = await signIn(); // Get user email here const email = ???; console.log(email); } catch (error) { console.error(error); } }; }
Attempts:
2 left
💡 Hint
Check the structure of the userInfo object returned by signIn().
✗ Incorrect
The userInfo object has a 'user' property containing user details including 'email'. Accessing userInfo.user.email is correct. Other options do not match the object structure.
🔧 Debug
expert3:00remaining
Debugging Apple Sign-In Token Expiry
A React Native app using Apple Sign-In sometimes fails to authenticate because the token is expired. Which approach fixes this issue?
Attempts:
2 left
💡 Hint
Tokens have limited lifetime and must be refreshed.
✗ Incorrect
Apple ID tokens expire after a short time. The app must request a fresh token each sign-in to authenticate successfully. Reusing old tokens or ignoring expiry causes failures.