forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

sfdx force:auth:web:login results in Cannot read properties of undefined (reading 'id') #1588

Closed MarcDBehr closed 1 year ago

MarcDBehr commented 2 years ago

Summary

Created a new dev sandbox. Then ran the command sfdx force:auth:web:login -r https://xxx--xxx.my.salesforce.com -a xxx. The web page opens and I log in. I get the message to accept the access, which I accept. Then I get redirected to a web page that says

"Cannot read properties of undefined (reading 'id')

This is most likely not an error with the Salesforce CLI. Please ensure all information is accurate and try again. "

and the CLI shows the same message ERROR running auth:web:login: Cannot read properties of undefined (reading 'id')

Steps To Reproduce:

  1. Create a new dev sandbox
  2. Attempt to authorize the org via the command line

Expected result

Successful connection to the org

Actual result

Error message

SCR-20220624-a20

System Information

$ sfdx version --verbose --json { "cliVersion": "sfdx-cli/7.156.1", "architecture": "darwin-x64", "nodeVersion": "node-v16.13.2", "pluginVersions": [ "@dx-cli-toolbox/sfdx-toolbox-package-utils 0.8.3", "@oclif/plugin-autocomplete 1.3.0", "@oclif/plugin-commands 1.3.0 (core)", "@oclif/plugin-help 3.3.1 (core)", "@oclif/plugin-not-found 1.2.6 (core)", "@oclif/plugin-plugins 1.10.11 (core)", "@oclif/plugin-update 1.5.0 (core)", "@oclif/plugin-warn-if-update-available 1.7.3 (core)", "@oclif/plugin-which 1.0.4 (core)", "@salesforce/lwc-dev-server 2.11.0", "@salesforce/sfdx-diff 0.0.6", "@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)", "alias 2.1.0 (core)", "apex 0.13.0 (core)", "auth 2.2.0 (core)", "bbdoc 4.0.5", "community 2.0.0 (core)", "config 1.4.12 (core)", "custom-metadata 2.0.0 (core)", "data 2.0.4 (core)", "generator 2.0.1 (core)", "info 2.0.1 (core)", "limits 2.0.1 (core)", "org 1.13.2 (core)", "salesforce-alm 54.6.0 (core)", "schema 2.1.1 (core)", "sfdmu 4.14.4", "sfdx-cli 7.156.1 (core)", "sfdx-flowdoc-plugin 0.5.1", "sfdx-waw-plugin 1.5.0", "sfpowerkit 4.2.8", "shane-sfdx-plugins 4.43.0", "├─ @mshanemc/plugin-streaming 1.1.7", "└─ @mshanemc/sfdx-sosl 1.1.0", "signups 1.2.0 (core)", "source 2.0.2 (core)", "telemetry 2.0.0 (core)", "templates 55.0.0 (core)", "trust 2.0.1 (core)", "user 2.1.0 (core)" ], "osVersion": "Darwin 21.5.0" }

Additional information

Feel free to attach a screenshot.

github-actions[bot] commented 2 years ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

MarcDBehr commented 2 years ago

After submitting, I dug in a bit more and found that the issue was that the new sandbox was created with Enhanced Domain enabled, so I would have specified sfdx force:auth:web:login -r https://xxx--xxx.sandbox.my.salesforce.com -a xxx. I think a better error message would have been nice to help point the user in the right direction

fransf-wtax commented 2 years ago

Getting the same error trying to authorize to my DevHub with auth:web:login.

sfdx auth:web:login -r http://xxx.my.salesforce.com -d -a devhub --json

{
  "status": 1,
  "name": "Type",
  "message": "Cannot read properties of undefined (reading 'id')",
  "exitCode": 1,
  "context": "Login",
  "stack": "Type: Cannot read properties of undefined (reading 'id')\n    at Function.wrap (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/node_modules/@salesforce/core/lib/sfError.js:61:25)\n    at Login.catch (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/node_modules/@salesforce/command/lib/sfdxCommand.js:267:38)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async Login._run (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/node_modules/@salesforce/command/lib/sfdxCommand.js:93:13)\n    at async Config.runCommand (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/node_modules/@oclif/config/lib/config.js:173:24)\n    at async SfdxMain.run (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/node_modules/@oclif/command/lib/main.js:27:9)\n    at async SfdxMain._run (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/node_modules/@oclif/command/lib/command.js:43:20)\n    at async Object.run (/Users/frans/.local/share/sfdx/client/7.156.1-6536039/dist/cli.js:162:47)",
  "warnings": [],
  "commandName": "Login"
}
fransf-wtax commented 2 years ago

I tried again without the -r and then it did work (sending me to login.salesforce.com to log in).

I think Salesforce either needs to document the use of this switch better, or fix whatever bug this is.

trentchilders commented 2 years ago

This issue is persisting for me. I used @MarcDBehr 's suggestion by using -r https://xxx--xxx.sandbox.my.salesforce.com but I continue to get the error Cannot read properties of undefined (reading 'id'). I cannot log in without the -r flag as my org uses custom domains.

mshanemc commented 2 years ago

@trentchilders can you update your cli and confirm that it's still happening? https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_update_cli.htm

If you are still getting the error on a current CLI, can you run the command with --dev-debug and share the output of that, along with answering the following:

  1. are you using enhanced domains on this sandbox?
  2. in ~/.sfdx/[this org's username].json is the instanceUrl correct?
trentchilders commented 2 years ago

@mshanemc Thanks for your quick response. Current sfdx version is sfdx-cli/7.159.0.

Running the login with dev-debug here: https://gist.github.com/trentchilders/42d34f4ab541ac8cd34cf89fef72c938

  1. Yes, enhanced domains are turned on
  2. This org is not yet in that folder
git2gus[bot] commented 2 years ago

This issue has been linked to a new work item: W-11477173

mshanemc commented 2 years ago

I think there's something changed about these new sandbox domains...does it get better after some time passes like it does for https://github.com/forcedotcom/cli/issues/1640 or stay broken?

peternhale commented 2 years ago

Anyone seen an improvement with this issue?

cherriges-he commented 2 years ago

I am encountering the same error today, 8/11/22. Are there any updates on a fix?

leboff commented 2 years ago

If it helps, using --instanceurl https://org--sbname.my.salesforce.com did not work, but --instanceurl https://test.salesforce.com did work (provided you dont have that "Prevent login from test..." option enabled)

tanish1804 commented 2 years ago

I am also facing this issue, and above solution didnt work. Is there any proper solution for it

rcopelandburgundy commented 2 years ago

In case anyone else has this issue, I was experiencing this by specifying an HTTP URL. Switching to HTTPS resolved the issue.

bvanburensky commented 2 years ago

I updated the scripts as follows to include the instance sfdx auth:web:login -r "https://xcorp--rockdevnew.my.salesforce.com" --setalias rockdevnew --setdefaultusername to sfdx auth:web:login -r "https://rockdevnew-xcorp.cs36.my.salesforce.com" --setalias rockdevnew --setdefaultusername

You can find the URL in setup/OrgDomain/home

BrunoRicci commented 2 years ago

After submitting, I dug in a bit more and found that the issue was that the new sandbox was created with Enhanced Domain enabled, so I would have specified sfdx force:auth:web:login -r https://xxx--xxx.sandbox.my.salesforce.com -a xxx. I think a better error message would have been nice to help point the user in the right direction

This worked to me! The difference is that I had to add ".sandbox" before ".my.salesforce.com". Once I put the command, the browser opened up and asked me to log in with my org credentials, as usual (the same that happened previously), and then it just worked fine: cmd terminal showed "Successfully authorized user@orgdomain.orgname with org ID **"

Thank you for letting us know your solution.

UptimaAlexx commented 2 years ago

Echo the ".sandbox" trick. Would recommend if the script can detect it's an ED, just parse the URL and pop in the not-so-intuitive ".sandbox".

sfdx force:auth:web:login -r https://xxx--xxx.sandbox.my.salesforce.com -a xxx

cristiand391 commented 1 year ago

this was fixed in v 7.172.0, see rel notes: https://github.com/forcedotcom/cli/tree/main/releasenotes/sfdx#71720-oct-13-2022