next-auth: Custom provider url undefined

Hi,

I’m using a custom provider and during the callback redirection to my website, I get this error that breaks npm:

internal/validators.js:117
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined

I tried to search around and can’t seem to understand where it comes form as all the required parameters to build the provider were passed.

Am I missing something?

Thanks in advance

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 26 (13 by maintainers)

Most upvoted comments

below the full error for reference:

Thanks, the full error is very helpful.

I suspect there is something wrong with your provider config, but I am not sure what. I would console.log() the output of the provider at run time. That error is happening because one of the values is empty. We can probably add some error handling to help point out which option is missing.

what is the right way to consume the Provider inside the Component?

Yes that’s right, that is as show on the documentation page and in the example project.

All that’s actually needed is:

import { Provider } from 'next-auth/client'

export default ({ Component, pageProps }) => {
  return (
    <Provider>
      <Component {...pageProps} />
    </Provider>
  )
}

But, as the tip in the documentation mentions below the example, you can add session={session} (using session from session.pageProps) as an optimisation.

Hi @iaincollins,

First of all, thanks for the effort you put in the answer, is really appreciated. I’ve updated to the beta.71 and enabled the getProfileFromToken: true. The result was an error that brakes execution in npm, below the output:

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _client=_interopRequireDefault(require("./client")),_querystring=_interopRequireDefault(require("querystring")),_jwtDecode=_interopRequireDefault(require("jwt-decode")),_logger=_interopRequireDefault(require("../../../lib/logger"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b

Error: Missing JWT token
    at _decodeToken ([redacted]\node_modules\next-auth\dist\server\lib\oauth\callback.js:1:4535)
    at [redacted]\node_modules\next-auth\dist\server\lib\oauth\callback.js:1:2117
    at [redacted]\node_modules\next-auth\dist\server\lib\oauth\callback.js:1:4227
    at passBackControl ([redacted]\node_modules\oauth\lib\oauth2.js:134:9)
    at IncomingMessage.<anonymous> ([redacted]\node_modules\oauth\lib\oauth2.js:157:7)
    at IncomingMessage.emit (events.js:323:22)
    at endReadableNT (_stream_readable.js:1204:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

The output of the console.log(profile) is undefined.

Regarding the provider, it’s an acquired solution from an Australian vendor based on .NET. The source-code is not available so I don’t know if they used a library or some kind of custom implementation.

I think the best is to abandon the idea of integrating this solution with next-auth and create a manual callback system that sets the token in a Cookie.

Let me know if you want to try something else to improve the library, but for me the issue can be closed.

I was changing the Auth0 config to simplify it (just added a PR) and when I had a typo in one of the required URLs I was having the same error as referred to in this issue. So I guess it’s probably just a wrong config? I’m not able to replicate it with custom providers unless there is a wrong URL.

Hmm this sounds like something is up with the Laravel Passport config, as I can see other people running into some of these errors using it with other libraries.

e.g. JSON_INVALID_UTF8_SUBSTITUTE is a PHP error.

I would ask the folks over at Laravel Passport if the config looks sane and for advice on common causes of that error.

I suspect the ERR_INVALID_ARG_TYPE arg is being throw from within next-auth (by a function it invokes) but I think it might be happening because either one of the URLs specified is invalid or returns an invalid response.

Hm okay, I thought it was OAuth missing some required options which were causing the error.

@nunorbatista try adding a scope: '' option too even if it’s just an empty one. I’m not sure if that will fix it but I think that might work.

@mavichow can you change options to params and check if that works? I think that’s the culprit.

I’m facing the same issue, I’m currently using Laravel Passport as my custom providers too and received below errors on the callback:

data: '{
"error": "unsupported_grant_type",
"error_description":"The authorization grant type is not supported by the authorization server.",
"hint":"Check that all required parameters have been provided",
"message":"The authorization grant type is not supported by the authorization server."
}'
internal/validators.js:121
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined

My oauth2 settings as bellow:

id               : 'laravel_passport',
name             : 'Laravel Passport',
type             : 'oauth',
version          : '2.0',
options          : { grant_type: 'authorization_code' },
accessTokenUrl   : 'http://localhost/laraval_passport/public/oauth/token',
requestTokenUrl  : 'http://localhost/laraval_passport/public/oauth/authorize',
authorizationUrl : 'http://localhost/laraval_passport/public/oauth/authorize?response_type=code',
clientId         : process.env.IDP_CLIENT_ID,
clientSecret     : process.env.IDP_CLIENT_SECRET

thanks!