Consider this NextAuth.js configuration snippet. What will be the value of token.userRole after a successful sign-in?
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.username === "admin" && credentials.password === "pass") { return { id: 1, name: "Admin User", role: "admin" }; } return null; } }) ], callbacks: { async jwt({ token, user }) { if (user) { token.userRole = user.role; } return token; } } });
Look at the authorize function and what it returns for the user object.
The authorize function returns a user object with a role property set to "admin" when credentials match. The jwt callback adds this role as userRole on the token. So after sign-in, token.userRole is "admin".
Choose the correct NextAuth.js provider configuration for Google OAuth.
Check the exact property names required by NextAuth.js Google provider.
The Google provider requires clientId and clientSecret properties matching environment variables. Option A uses the correct import and property names.
Examine this session callback code. What error will it cause when running?
callbacks: {
async session({ session, token }) {
session.user.id = token.sub;
session.user.role = token.userRole;
return session;
}
}The session.user object is always available and mutable in the session callback.
No error occurs. The session object always includes a user property that is an object. You can safely set additional properties like id and role. This is a common and documented pattern in NextAuth.js.
session.user.email after sign-in with this NextAuth.js config?Given this NextAuth.js configuration, what will session.user.email be after a user signs in?
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 }) ], callbacks: { async session({ session, token }) { session.user.email = token.email ?? "no-email@example.com"; return session; }, async jwt({ token, user, account }) { if (user) { token.email = user.email; } return token; } } });
Look at how the jwt callback sets token.email and how session callback uses it.
The jwt callback sets token.email from the user object after sign-in. The session callback then assigns session.user.email from token.email. So it will be the user's GitHub email.
NextAuth.js supports adapters to connect to databases. Which of these statements is true about using an adapter?
Think about when adapters are necessary and how sessions can be managed.
Adapters let NextAuth.js save user accounts and sessions in a database. They are optional if you use JWT sessions, which store session data in tokens instead of a database.