Skip to content

Commit

Permalink
fix: replace .flat() to support Node <11 again (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamauri committed Apr 11, 2021
1 parent a7709df commit 872e180
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ async function NextAuthHandler (req, res, userOptions) {
provider.protection = 'state' // Default to state, as we did in 3.1 REVIEW: should we use "pkce" or "none" as default?
}

if (typeof provider.protection === 'string') {
provider.protection = [provider.protection]
}

const maxAge = 30 * 24 * 60 * 60 // Sessions expire after 30 days of being idle

// Parse database / adapter
Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/oauth/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function getOAuth2AccessToken (code, provider, codeVerifier) {
headers.Authorization = `Bearer ${code}`
}

if ([provider.protection].flat().includes('pkce')) {
if (provider.protection.includes('pkce')) {
params.code_verifier = codeVerifier
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/lib/oauth/pkce-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const PKCE_MAX_AGE = 60 * 15 // 15 minutes in seconds
export async function handleCallback (req, res) {
const { cookies, provider, baseUrl, basePath } = req.options
try {
if (![provider.protection].flat().includes('pkce')) { // Provider does not support PKCE, nothing to do.
if (!provider.protection.includes('pkce')) { // Provider does not support PKCE, nothing to do.
return
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export async function handleCallback (req, res) {
export async function handleSignin (req, res) {
const { cookies, provider, baseUrl, basePath } = req.options
try {
if (![provider.protection].flat().includes('pkce')) { // Provider does not support PKCE, nothing to do.
if (!provider.protection.includes('pkce')) { // Provider does not support PKCE, nothing to do.
return
}
// Started login flow, add generated pkce to req.options and (encrypted) code_verifier to a cookie
Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/oauth/state-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { OAuthCallbackError } from '../../../lib/errors'
export async function handleCallback (req, res) {
const { csrfToken, provider, baseUrl, basePath } = req.options
try {
if (![provider.protection].flat().includes('state')) { // Provider does not support state, nothing to do.
if (!provider.protection.includes('state')) { // Provider does not support state, nothing to do.
return
}

Expand Down

1 comment on commit 872e180

@vercel
Copy link

@vercel vercel bot commented on 872e180 Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.