Skip to content

Error on missing profileUrl and/or profile #1065

@jackHedaya

Description

@jackHedaya

Describe the bug
In the documentation, profileUrl and profile for custom providers are said to be not required in documentation but the application will crash if they are not given. This error is also the root of issue #209 as discovered by @ospira.

Steps to reproduce
Steps to reproduce the behavior.

  • Create custom provider
  • Omit profileUrl and/or profile

Expected behavior
Authentication to succeed and profile to be set to undefined.

Screenshots or error logs

[next-auth][error][oauth_get_access_token_error] [
  TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
      at new NodeError (node:internal/errors:278:15)
      at validateString (node:internal/validators:123:11)
      at Url.parse (node:url:160:3)
      at Object.urlParse [as parse] (node:url:155:13)
      at exports.OAuth2._request (/Users/jackhedaya/Desktop/thoughtful-fish/node_modules/oauth/lib/oauth2.js:72:22)
      at /Users/jackhedaya/Desktop/thoughtful-fish/node_modules/next-auth/dist/server/lib/oauth/client.js:240:12
      at new Promise (<anonymous>)
      at exports.OAuth2.<anonymous> (/Users/jackhedaya/Desktop/thoughtful-fish/node_modules/next-auth/dist/server/lib/oauth/client.js:239:12)
     ...

Additional context
Original custom Provider:

NextAuth(req, res, {
    providers: [
      {
        id: '[redacted]',
        name: '[redacted]',
        type: 'oauth',
        version: '2.0',
        accessTokenUrl: '[redacted]',
        requestTokenUrl: '[redacted]',
        authorizationUrl: `[redacted]`,
        clientId: process.env.CONSUMER_KEY,
        params: {
          grant_type: 'authorization_code',
        },
      },
    ],
    debug: true,
  })

Working custom provider:

NextAuth(req, res, {
    providers: [
      {
        id: '[redacted]',
        name: '[redacted]',
        type: 'oauth',
        version: '2.0',
        accessTokenUrl: '[redacted]',
        requestTokenUrl: '[redacted]',
        authorizationUrl: `[redacted]`,
        clientId: process.env.CONSUMER_KEY,
        params: {
          grant_type: 'authorization_code',
        },
        profileUrl: '[redacted]',
        profile: (p) => {
          return {
            id: p.userId
          }
        },
      },
    ],
    debug: true,
  })
  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful

Metadata

Metadata

Assignees

Labels

docsRelates to documentationhelp-neededThe maintainer needs help due to time constraint/missing knowledgestaleDid not receive any activity for 60 days

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions