C. Incorrect import syntax; should use default import without braces
D. NextAuth must be imported from 'next-auth/client'
Solution
Step 1: Check import style for GithubProvider
GithubProvider is the default export, so it should be imported without braces.
Step 2: Identify correct import syntax
Use import GithubProvider from "next-auth/providers/github"; instead of curly braces.
Final Answer:
Incorrect import syntax; should use default import without braces -> Option C
Quick Check:
Default export = no braces in import [OK]
Hint: Default exports import without braces {} [OK]
Common Mistakes:
Using named import syntax for default export
Assuming environment variables cause this error
Placing provider config inside callbacks
5. You want to add Google and GitHub login providers in NextAuth.js with environment variables. Which is the correct way to configure both providers in /pages/api/auth/[...nextauth].js?
hard
A. import GoogleProvider from "next-auth/providers/google";
import GithubProvider from "next-auth/providers/github";
export default NextAuth({
providers: [
GoogleProvider({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET }),
GithubProvider({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET })
]
});
B. import { GoogleProvider, GithubProvider } from "next-auth/providers";
export default NextAuth({
providers: [
GoogleProvider(process.env.GOOGLE_ID, process.env.GOOGLE_SECRET),
GithubProvider(process.env.GITHUB_ID, process.env.GITHUB_SECRET)
]
});
C. import GoogleProvider from "next-auth/providers/google";
import GithubProvider from "next-auth/providers/github";
export default NextAuth({
providers: {
google: GoogleProvider,
github: GithubProvider
}
});
D. import GoogleProvider from "next-auth/providers/google";
import GithubProvider from "next-auth/providers/github";
export default NextAuth({
providers: [
GoogleProvider,
GithubProvider
]
});
Solution
Step 1: Import providers correctly
Each provider is a default export from its own module and must be imported separately.
Step 2: Configure providers as array with clientId and clientSecret
Providers must be called as functions with an object containing clientId and clientSecret from environment variables.
Step 3: Validate options
import GoogleProvider from "next-auth/providers/google";
import GithubProvider from "next-auth/providers/github";
export default NextAuth({
providers: [
GoogleProvider({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET }),
GithubProvider({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET })
]
}); correctly imports and configures both providers in an array with proper keys.
Final Answer:
Correct import and provider function calls with env variables -> Option A