When I tried the first curl command, I got a 401 Unauthorized so I went and copied from the notes in case I had made a mistake, but the error remains. Any idea what would be stopping me from getting an auth_token returned? My logs show the following: Processing by SessionsController#create as /
Parameters: {"'{email:john@example.com,password:1234}'"=>"[FILTERED]"} SELECT "users".* FROM "users" WHERE "users"."email" IS NULL LIMIT ? [["LIMIT", 1]]
Completed 401 Unauthorized.
I also created the user in the same way as the video shows, with a name, password, and password_confirmation.
Is the curl request in the notes malformed? I am only changing the values of the email and password like so:
curl -H 'Content-Type: application/json' -X POST -d '{"email":"john@example.com","password":"1234"}' http://localhost:3000/authenticate
Thank you for the very prompt reply!
Curl version:
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Ruby version:
ruby 2.4.4p296 (2018-03-28 revision 63013) [x64-mingw32]
Line 17 of authenticate_user has the safe navigation operator which could potentially be causing issues, but I just checked and that was added in ruby 2.3.
Perhaps this is just an issue with development on windows, but I haven't had issues with curl in the past.
It ended up being an issue with how quotes are interpreted for windows cmd. I was able to get it working by replacing all the single quotes with double quotes and then escaping the double quotes for the arguments like so:
curl -H "Content-Type:application/json" -X POST -d "{\"email\": \"john@example.com\", \"password\": \"1234\"}" http://localhost:3000/authenticate
Thanks again. I will spin up an ubuntu server vm later but I didn't feel like dealing with the setup tonight.
One other thing, I think it would be good to mention your episode #123 Encrypted Credentials in Rails 5.2 as the setup in this is required, at least for generating the credentials.yml.enc and master.key.