0
0
Firebasecloud~10 mins

Facebook sign-in in Firebase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Facebook sign-in
User clicks Facebook Sign-In button
App calls Firebase Facebook Auth
Firebase opens Facebook login popup
User enters Facebook credentials
Facebook verifies credentials
Facebook returns access token to Firebase
Firebase verifies token and signs in user
App receives user info and updates UI
The user clicks the Facebook sign-in button, triggering Firebase to open a Facebook login popup. After the user logs in, Facebook sends a token to Firebase, which verifies it and signs in the user.
Execution Sample
Firebase
const provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithPopup(provider)
  .then((result) => {
    const user = result.user;
    console.log('User signed in:', user.displayName);
  })
  .catch((error) => console.error(error));
This code triggers a Facebook login popup via Firebase and logs the signed-in user's name on success.
Process Table
StepActionFirebase StateFacebook StateResult
1User clicks Facebook sign-in buttonIdleIdlePopup triggered
2Firebase opens Facebook login popupWaiting for Facebook loginWaiting for user inputPopup visible
3User enters Facebook credentialsWaiting for Facebook responseVerifying credentialsCredentials submitted
4Facebook verifies credentialsWaiting for tokenVerified credentialsAccess token generated
5Facebook returns access token to FirebaseVerifying tokenToken sentToken received
6Firebase verifies token and signs in userSigned inIdleUser authenticated
7App receives user info and updates UISigned inIdleUser info displayed
8Process completeSigned inIdleReady for next action
💡 User successfully signed in after Firebase verified Facebook token
Status Tracker
VariableStartAfter Step 3After Step 5Final
providerundefinedFacebookAuthProvider instanceFacebookAuthProvider instanceFacebookAuthProvider instance
resultundefinedundefinedAuth result with tokenAuth result with user info
userundefinedundefinedundefinedUser object with displayName
Key Moments - 3 Insights
Why does the app open a popup instead of redirecting immediately?
The popup allows the app to keep control and handle the login without leaving the page, as shown in execution_table step 2.
What happens if the user enters wrong Facebook credentials?
Firebase will catch an error in the catch block (not shown in table), preventing sign-in and showing an error message.
Why do we need to verify the Facebook token in Firebase?
Firebase verifies the token to ensure it is valid and issued by Facebook, securing the sign-in process as in execution_table step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Firebase receive the Facebook access token?
AStep 5
BStep 3
CStep 6
DStep 7
💡 Hint
Check the 'Result' column for when the token is received by Firebase.
According to the variable tracker, when is the 'user' variable first assigned a value?
AAfter Step 3
BAfter Step 5
CFinal
DStart
💡 Hint
Look at the 'user' row and see when it changes from undefined.
If the user cancels the Facebook login popup, what would happen in the execution flow?
AFirebase signs in the user anyway
BFirebase catches an error and sign-in fails
CThe popup stays open indefinitely
DUser info is displayed without login
💡 Hint
Consider what happens when credentials are not provided or login is aborted.
Concept Snapshot
Facebook sign-in with Firebase:
- Create FacebookAuthProvider instance
- Call signInWithPopup(provider)
- User logs in via popup
- Facebook returns access token
- Firebase verifies token and signs in user
- App receives user info and updates UI
- Errors handled in catch block
Full Transcript
This visual execution traces the Facebook sign-in process using Firebase. The user clicks the sign-in button, triggering Firebase to open a Facebook login popup. The user enters credentials, which Facebook verifies and returns as an access token. Firebase then verifies this token and signs in the user. The app receives the user information and updates the interface accordingly. Variables like 'provider', 'result', and 'user' change state through the process. Key moments include understanding why a popup is used, error handling for wrong credentials, and token verification for security. The quizzes test understanding of token receipt, variable assignment, and error scenarios.