Complete the code to import the Next.js session hook.
import { [1] } from 'next-auth/react';
The useSession hook is used to access session data in Next.js components.
Complete the code to get the session data inside a React component.
const { data: session, status } = [1]();useSession() returns the session data and status inside React components.
Fix the error in the server-side session fetching code.
import { getSession } from 'next-auth/react'; export async function getServerSideProps(context) { const session = await [1](context); return { props: { session } }; }
getSession(context) is the correct function to fetch session data server-side in Next.js.
Fill both blanks to sign in a user with credentials and redirect after success.
import { signIn } from 'next-auth/react'; async function handleLogin() { const result = await signIn('[1]', { redirect: [2] }); }
Use 'credentials' as the provider name and redirect: false to handle redirects manually.
Fill all three blanks to create a session-aware API route that returns the user's email or an error.
import { getSession } from 'next-auth/react'; export default async function handler(req, res) { const session = await [1](req[2]); if (!session) { return res.status(401).json({ error: 'Unauthorized' }); } res.status(200).json({ email: session.user[3] }); }
getSession(req) fetches the session from the request. The request object is passed directly. Access the email via session.user.email.