Complete the code to check if the user is authenticated in the context.
if (!context.[1]) { throw new Error('Not authenticated'); }
The context.user property usually holds the authenticated user information. Checking if it exists helps determine if the user is authenticated.
Complete the code to throw an authentication error with a specific message.
throw new [1]('Authentication failed');
AuthenticationError is a common custom error type used to indicate authentication failures in GraphQL APIs.
Fix the error in the code to correctly access the authentication token from context headers.
const token = context.req.headers.[1];The HTTP header for authentication tokens is usually authorization in lowercase when accessed in Node.js request headers.
Fill both blanks to extract the token from the authorization header string.
const token = context.req.headers.authorization?.[1](' ')[[2]];
The authorization header usually has the format 'Bearer TOKEN'. Splitting by space and taking the second part (index 1) extracts the token.
Fill all three blanks to verify the token and attach the user to context.
const user = await verifyToken([1]); if (!user) { throw new AuthenticationError('Invalid token'); } context.[2] = user; return [3];
The token is passed to verifyToken. If valid, the user is attached to context.user. Finally, the user object is returned.