Hint: Token user data matches currentUser fields returned [OK]
Common Mistakes:
Expecting null or error despite valid token
Confusing error response with data
Assuming fields return null values
4. A developer tries to use federated authentication but gets an "Unauthorized" error. Which fix will most likely solve the problem?
medium
A. Add the token in the request header as "Authorization: Bearer <token>".
B. Remove the token from the request to allow anonymous access.
C. Change the query to request only public fields.
D. Use a different GraphQL query without authentication.
Solution
Step 1: Identify cause of Unauthorized error
Unauthorized usually means missing or invalid authentication token in the request.
Step 2: Apply correct token header format
Adding the token properly as "Authorization: Bearer <token>" header will authenticate the user and fix the error.
Final Answer:
Add the token in the request header as "Authorization: Bearer <token>". -> Option A
Quick Check:
Unauthorized error = missing or wrong token header [OK]
Hint: Always send token in Authorization header [OK]
Common Mistakes:
Removing token expecting anonymous access
Changing query without fixing auth
Using wrong header names or formats
5. You want to implement federated authentication in a GraphQL API that supports multiple identity providers (Google, Facebook, GitHub). Which approach best handles user identity across these providers?
hard
A. Map external provider user IDs to a single internal user ID in your database.
B. Create separate user records for each provider's user ID without linking.
C. Require users to manually link accounts after login.
D. Ignore provider IDs and use only email addresses to identify users.