In a Next.js app using NextAuth.js, what happens immediately after a user successfully signs in with an OAuth provider?
import NextAuth from "next-auth"; import GitHubProvider from "next-auth/providers/github"; export default NextAuth({ providers: [ GitHubProvider({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET }) ], pages: { signIn: '/auth/signin' }, callbacks: { async redirect({ url, baseUrl }) { return url.startsWith(baseUrl) ? url : baseUrl; } }, debug: false });
Consider the role of the redirect callback after successful authentication.
NextAuth.js automatically redirects the user to the URL returned by the redirect callback or the default base URL after successful sign-in.
Which option correctly configures the Google OAuth provider credentials in NextAuth.js?
import NextAuth from "next-auth"; import GoogleProvider from "next-auth/providers/google"; export default NextAuth({ providers: [ GoogleProvider({ clientId: "your-client-id", clientSecret: "your-client-secret" }) ] });
Check the exact property names required by the provider.
The correct property names are clientId and clientSecret. Using environment variables is best practice.
Given this NextAuth.js credential provider configuration, what error will occur and why?
import NextAuth from "next-auth"; import CredentialsProvider from "next-auth/providers/credentials"; export default NextAuth({ providers: [ CredentialsProvider({ name: "Credentials", credentials: { username: { label: "Username", type: "text" }, password: { label: "Password", type: "password" } }, async authorize(credentials) { if (!credentials) return null; if (credentials.username === "admin" && credentials.password === "pass") { return { id: 1, name: "Admin" }; } return null; } }) ] });
Consider what happens if credentials is undefined.
If credentials is undefined, accessing credentials.username causes a TypeError. A check for credentials is needed before accessing its properties.
After a user signs in with an OAuth provider in NextAuth.js, what does the session object typically contain?
import { useSession } from "next-auth/react"; export default function Profile() { const { data: session } = useSession(); return <pre>{JSON.stringify(session, null, 2)}</pre>; }
Think about what information NextAuth.js stores in session by default.
NextAuth.js session object includes user info like name, email, image, and an expiration timestamp. Access tokens may be added via callbacks.
What is the main security risk if OAuth client secrets are exposed in client-side Next.js code instead of server-side configuration?
Consider what client secrets protect and who can access client-side code.
Client secrets must be kept private on the server. Exposing them in client code allows attackers to misuse the app's identity with the OAuth provider.