Skip to content

Commit a7d34f9

Browse files
fix(providers): properly warn when using Twitter OAuth 2 (#3784)
* 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
1 parent f20d679 commit a7d34f9

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/core/lib/assert.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ export function assertConfig(
4545
if (!req.host) return "NEXTAUTH_URL"
4646

4747
let hasCredentials, hasEmail
48+
let hasTwitterProvider
4849

49-
options.providers.forEach(({ type }) => {
50-
if (type === "credentials") hasCredentials = true
51-
else if (type === "email") hasEmail = true
52-
})
50+
for (const provider of options.providers) {
51+
if (provider.type === "credentials") hasCredentials = true
52+
else if (provider.type === "email") hasEmail = true
53+
else if (provider.id === "twitter") hasTwitterProvider = true
54+
}
5355

5456
if (hasCredentials) {
5557
const dbStrategy = options.session?.strategy === "database"
@@ -75,4 +77,8 @@ export function assertConfig(
7577
if (hasEmail && !options.adapter) {
7678
return new MissingAdapter("E-mail login requires an adapter.")
7779
}
80+
81+
if (hasTwitterProvider) {
82+
return "TWITTER_OAUTH_2_BETA"
83+
}
7884
}

src/lib/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function hasErrorProperty(
1919
return !!(x as any)?.error
2020
}
2121

22-
export type WarningCode = "NEXTAUTH_URL" | "NO_SECRET"
22+
export type WarningCode = "NEXTAUTH_URL" | "NO_SECRET" | "TWITTER_OAUTH_2_BETA"
2323

2424
/**
2525
* Override any of the methods, and the rest will use the default logger.

src/providers/twitter.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,10 @@ export interface TwitterProfile {
166166
}
167167
}
168168

169-
let warned = false
170169
export default function Twitter<
171170
P extends Record<string, any> = TwitterLegacyProfile | TwitterProfile
172171
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
173-
if (!warned && options.version === "2.0") {
174-
warned = true
175-
console.warn(
176-
"Opted-in to Twitter OAuth 2.0. See the docs https://next-auth.js.org/providers/twitter#oauth-2"
177-
)
172+
if (options.version === "2.0") {
178173
return {
179174
id: "twitter",
180175
name: "Twitter",

0 commit comments

Comments
 (0)