Skip to content

Commit

Permalink
fix(providers): properly warn when using Twitter OAuth 2 (#3784)
Browse files Browse the repository at this point in the history
* fix(providers): properly warn when using Twitter OAuth 2

* refactor(providers): move Twitter OAuth2 warning to `assert`

* fix: use proper warning code

* refactor: only set boolean
  • Loading branch information
balazsorban44 committed Feb 2, 2022
1 parent f20d679 commit a7d34f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/core/lib/assert.ts
Expand Up @@ -45,11 +45,13 @@ export function assertConfig(
if (!req.host) return "NEXTAUTH_URL"

let hasCredentials, hasEmail
let hasTwitterProvider

options.providers.forEach(({ type }) => {
if (type === "credentials") hasCredentials = true
else if (type === "email") hasEmail = true
})
for (const provider of options.providers) {
if (provider.type === "credentials") hasCredentials = true
else if (provider.type === "email") hasEmail = true
else if (provider.id === "twitter") hasTwitterProvider = true
}

if (hasCredentials) {
const dbStrategy = options.session?.strategy === "database"
Expand All @@ -75,4 +77,8 @@ export function assertConfig(
if (hasEmail && !options.adapter) {
return new MissingAdapter("E-mail login requires an adapter.")
}

if (hasTwitterProvider) {
return "TWITTER_OAUTH_2_BETA"
}
}
2 changes: 1 addition & 1 deletion src/lib/logger.ts
Expand Up @@ -19,7 +19,7 @@ function hasErrorProperty(
return !!(x as any)?.error
}

export type WarningCode = "NEXTAUTH_URL" | "NO_SECRET"
export type WarningCode = "NEXTAUTH_URL" | "NO_SECRET" | "TWITTER_OAUTH_2_BETA"

/**
* Override any of the methods, and the rest will use the default logger.
Expand Down
7 changes: 1 addition & 6 deletions src/providers/twitter.ts
Expand Up @@ -166,15 +166,10 @@ export interface TwitterProfile {
}
}

let warned = false
export default function Twitter<
P extends Record<string, any> = TwitterLegacyProfile | TwitterProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
if (!warned && options.version === "2.0") {
warned = true
console.warn(
"Opted-in to Twitter OAuth 2.0. See the docs https://next-auth.js.org/providers/twitter#oauth-2"
)
if (options.version === "2.0") {
return {
id: "twitter",
name: "Twitter",
Expand Down

0 comments on commit a7d34f9

Please sign in to comment.