Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New users must run init twice #372

Closed
arneke opened this issue Nov 22, 2017 · 8 comments
Closed

New users must run init twice #372

arneke opened this issue Nov 22, 2017 · 8 comments

Comments

@arneke
Copy link

arneke commented Nov 22, 2017

Definitely minor, but a bit of a buzzkiller for first time users:

mkdir sanity
cd sanity/
npm install -g @sanity/cli

/usr/local/bin/sanity -> /usr/local/lib/node_modules/@sanity/cli/bin/sanity.js

> spawn-sync@1.0.15 postinstall /usr/local/lib/node_modules/@sanity/cli/node_modules/spawn-sync
> node postinstall

+ @sanity/cli@0.121.0
added 245 packages in 35.272s

sanity init

This utility walks you through creating a Sanity installation.
Press ^C at any time to quit.

We can't find any auth credentials in your Sanity config - looks like you
haven't used Sanity on this system before?

? Login type Google

Opening browser at https://api.sanity.io/v1/auth/login/google?origin=http%3A%2F%2Flocalhost%3A60734%2Freturn&type=token&label=reti.local%20%2F%20darwin

Login successful

Script terminates. Then, if you follow the step-by-step instructions:

sanity start

"start" is not available outside of a Sanity project context.
Run the command again within a Sanity project directory, where "@sanity/core"
is installed as a dependency.

Huh?

ls -alh

total 0
drwxr-xr-x    2 ak  staff    68B Nov 22 08:46 .
drwxr-xr-x+ 197 ak  staff   6.5K Nov 22 08:46 ..

Second attempt works:
sanity init

This utility walks you through creating a Sanity installation.
Press ^C at any time to quit.

Looks like you already have a Sanity-account. Sweet!

? Project name ...
@rexxars
Copy link
Member

rexxars commented Nov 22, 2017

Huh, that's strange. Tried on a few different computers now, and can't seem to reproduce this...
Which operating system and node version are you running?

@arneke
Copy link
Author

arneke commented Nov 22, 2017

node 8.7.0, macOS Sierra 10.12.6, default browser is Chrome.

I can try again (either with the same or a different Google account) on node 8.9.2 if you tell me what files to clear.

@rexxars
Copy link
Member

rexxars commented Nov 22, 2017

Should be enough with a sanity logout

@arneke
Copy link
Author

arneke commented Nov 22, 2017

On my machine (which is far from clean) it is reproducible, also on node 8.9.2.

Ran sanity logout , created new directory and ran sanity init again. Stopped after the Login successful message, exit code was 0.

I looked a bit more into it

  sanity:cli Starting OAuth receiver webserver +4s
  sanity:cli Webserver listening, opening browser +4ms

Opening browser at https://api.sanity.io/v1/auth/login/google?origin=http%3A%2F%2Flocalhost%3A55949%2Freturn&type=token&label=reti.local%20%2F%20darwin

⠋ Waiting for browser login flow to complete... Press Ctrl + C to cancel  sanity:cli Request received, exchanging token for a long-lived one +899ms
  sanity:client [2] HTTP GET https://api.sanity.io/v1/auth/fetch?sid=... +5ms
  sanity:client [2] Request headers: {
  "Accept": "application/json",
  "User-Agent": "@sanity/client 0.121.0"
} +1ms
⠹ Waiting for browser login flow to complete... Press Ctrl + C to cancel  sanity:client [2] Response code: 200 OK +159ms
  sanity:client [2] Response body: {
  "token": "...",
  "label": "reti.local / darwin"
} +0ms
  sanity:cli Token exchange complete, serving page +1ms
  sanity:cli Storing the login token +4ms
Login successful

I dug a bit around, added some more console statements:

https://github.com/sanity-io/sanity/blob/master/packages/%40sanity/cli/src/actions/login/login.js#L114
is being run, but
https://github.com/sanity-io/sanity/blob/master/packages/%40sanity/cli/src/actions/login/login.js#L115 is not.

Haven't had time to look into the next step, what should have ended the server process.

@rexxars
Copy link
Member

rexxars commented Nov 22, 2017

Thanks for digging into this! I'm not sure exactly why node is exiting before the promise has been resolved, but it seems unnecessary to wait until the server has closed anyway, so I should be able to refactor this quite easily.

Will let you know once I have a new release candidate you can try out.

@rexxars
Copy link
Member

rexxars commented Nov 23, 2017

@arneke Debugging this is a little hard since I'm not able to reproduce this, but could you try the following:

npm install -g @sanity/cli@cli-next
sanity logout
sanity init

And see if it has the same issue?

@arneke
Copy link
Author

arneke commented Nov 23, 2017

cli-next worked for me

@rexxars
Copy link
Member

rexxars commented Nov 24, 2017

Thanks for reporting!
We've fixed this in v0.122.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants