( params: NextAuthHandlerParams )
| 25 | * REVIEW: Make some of these and corresponding docs less Next.js specific? |
| 26 | */ |
| 27 | export function assertConfig( |
| 28 | params: NextAuthHandlerParams |
| 29 | ): ConfigError | WarningCode | undefined { |
| 30 | const { options, req } = params |
| 31 | |
| 32 | // req.query isn't defined when asserting `getServerSession` for example |
| 33 | if (!req.query?.nextauth && !req.action) { |
| 34 | return new MissingAPIRoute( |
| 35 | "Cannot find [...nextauth].{js,ts} in `/pages/api/auth`. Make sure the filename is written correctly." |
| 36 | ) |
| 37 | } |
| 38 | |
| 39 | if (!options.secret) { |
| 40 | if (process.env.NODE_ENV === "production") { |
| 41 | return new MissingSecret("Please define a `secret` in production.") |
| 42 | } else { |
| 43 | return "NO_SECRET" |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (!req.host) return "NEXTAUTH_URL" |
| 48 | |
| 49 | let hasCredentials, hasEmail |
| 50 | let hasTwitterProvider |
| 51 | |
| 52 | for (const provider of options.providers) { |
| 53 | if (provider.type === "credentials") hasCredentials = true |
| 54 | else if (provider.type === "email") hasEmail = true |
| 55 | else if (provider.id === "twitter") hasTwitterProvider = true |
| 56 | } |
| 57 | |
| 58 | if (hasCredentials) { |
| 59 | const dbStrategy = options.session?.strategy === "database" |
| 60 | const onlyCredentials = !options.providers.some( |
| 61 | (p) => p.type !== "credentials" |
| 62 | ) |
| 63 | if (dbStrategy && onlyCredentials) { |
| 64 | return new UnsupportedStrategy( |
| 65 | "Signin in with credentials only supported if JWT strategy is enabled" |
| 66 | ) |
| 67 | } |
| 68 | |
| 69 | const credentialsNoAuthorize = options.providers.some( |
| 70 | (p) => p.type === "credentials" && !p.authorize |
| 71 | ) |
| 72 | if (credentialsNoAuthorize) { |
| 73 | return new MissingAuthorize( |
| 74 | "Must define an authorize() handler to use credentials authentication provider" |
| 75 | ) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (hasEmail && !options.adapter) { |
| 80 | return new MissingAdapter("E-mail login requires an adapter.") |
| 81 | } |
| 82 | |
| 83 | if (!twitterWarned && hasTwitterProvider) { |
| 84 | twitterWarned = true |
no outgoing calls
no test coverage detected
searching dependent graphs…