0
0
React Nativemobile~20 mins

Authentication (email, Google, Apple) in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Authentication Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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>
  );
}
AAn alert pops up saying 'Error: Email and password are required'.
BThe app crashes with a runtime error.
CAn alert pops up saying 'Success: Logging in...'.
DNothing happens when the button is tapped.
Attempts:
2 left
💡 Hint
Check the condition inside the handleLogin function that checks if email or password is empty.
🧠 Conceptual
intermediate
1: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?
ATo refresh the user's Google password automatically.
BTo authenticate the user on your backend server securely.
CTo display the user's email on the screen.
DTo log the user out of their Google account.
Attempts:
2 left
💡 Hint
Think about why your app backend needs a token from Google.
lifecycle
advanced
2: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?
AThe app receives an error indicating the user cancelled the sign-in.
BThe app automatically retries the sign-in process.
CThe app crashes due to unhandled promise rejection.
DThe app signs the user in anonymously.
Attempts:
2 left
💡 Hint
Consider how the Apple Sign-In API communicates cancellation.
📝 Syntax
advanced
2: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);
    }
  };
}
Aconst email = userInfo.profile.email;
Bconst email = userInfo.email;
Cconst email = userInfo.user.email;
Dconst email = userInfo.getEmail();
Attempts:
2 left
💡 Hint
Check the structure of the userInfo object returned by signIn().
🔧 Debug
expert
3: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?
AUse the Google Sign-In token instead of Apple ID token.
BStore the token indefinitely and reuse it for all sessions.
CIgnore token expiry and proceed with authentication anyway.
DRequest a new Apple ID token each time the user signs in, instead of reusing old tokens.
Attempts:
2 left
💡 Hint
Tokens have limited lifetime and must be refreshed.