ryanswapp / react-phoenix-starter-template

This is an example repo of using React with Phoenix
99 stars 6 forks source link

Error when logged in #6

Closed AdamBrodzinski closed 8 years ago

AdamBrodzinski commented 8 years ago

When I am not logged in and just visit the home page I get a 401 error (and plug says it's denied) and when I log in (jwt in localstorage btw) I get this error:

[info] GET /api/v1/current_user
[debug] SELECT u0."id", u0."username", u0."email", u0."password_hash", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."id" = $1) [1] OK query=0.7ms
[debug] Processing by ReactPhoenix.V1.UserController.current_user/2
  Parameters: %{}
  Pipelines: [:api]
[info] Sent 400 in 31ms
[error] #PID<0.382.0> running ReactPhoenix.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /api/v1/current_user
** (exit) an exception was raised:
    ** (Phoenix.ActionClauseError) bad request to ReactPhoenix.V1.UserController.current_user, no matching action clause to process request
        (react_phoenix) web/controllers/v1/user_controller.ex:63: ReactPhoenix.V1.UserController.current_user(%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{guardian_default_claims: {:ok, %{"aud" => "token", "exp" => 1449096719, "iat" => 1448837519, "iss" => "ReactPhoenix", "jti" => "6c97350a-3c52-47a6-ac18-b58494f07848", "pem" => %{}, "sub" => "User:1"}}, guardian_default_jwt: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVc2VyOjEiLCJwZW0iOnt9LCJqdGkiOiI2Yzk3MzUwYS0zYzUyLTQ3YTYtYWMxOC1iNTg0OTRmMDc4NDgiLCJpc3MiOiJSZWFjdFBob2VuaXgiLCJpYXQiOjE0NDg4Mzc1MTksImV4cCI6MTQ0OTA5NjcxOSwiYXVkIjoidG9rZW4ifQ.r7KYf6RzKhiPPRmhty-MwgMtBAtUU_JobVMWsp797pg", guardian_default_resource: %ReactPhoenix.User{__meta__: #Ecto.Schema.Metadata<:loaded>, email: "adambrodzinski@gmail.com", id: 1, inserted_at: #Ecto.DateTime<2015-11-29T22:51:07Z>, password: nil, password_hash: "$2b$12$EpqaIQqG5v1pY5W3ZV22ouvZkoDaFB7Z5FFADoCGAqSPxPi8InG1e", updated_at: #Ecto.DateTime<2015-11-29T22:51:07Z>, username: "SkinnyGeek1010"}}, before_send: [#Function<1.15586404/1 in Plug.Logger.call/2>, #Function<0.59356453/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>], body_params: %{}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "localhost", method: "GET", owner: #PID<0.382.0>, params: %{}, path_info: ["api", "v1", "current_user"], peer: {{127, 0, 0, 1}, 52311}, port: 4000, private: %{ReactPhoenix.Router => {[], %{}}, :phoenix_action => :current_user, :phoenix_controller => ReactPhoenix.V1.UserController, :phoenix_endpoint => ReactPhoenix.Endpoint, :phoenix_format => "json", :phoenix_layout => {ReactPhoenix.LayoutView, :app}, :phoenix_pipelines => [:api], :phoenix_route => #Function<7.5837934/1 in ReactPhoenix.Router.match/4>, :phoenix_router => ReactPhoenix.Router, :phoenix_view => ReactPhoenix.V1.UserView, :plug_session_fetch => #Function<1.51196796/1 in Plug.Session.fetch_session/1>}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [{"host", "localhost:4000"}, {"connection", "keep-alive"}, {"accept", "application/json, text/plain, */*"}, {"origin", "http://localhost:3000"}, {"user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"}, {"authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVc2VyOjEiLCJwZW0iOnt9LCJqdGkiOiI2Yzk3MzUwYS0zYzUyLTQ3YTYtYWMxOC1iNTg0OTRmMDc4NDgiLCJpc3MiOiJSZWFjdFBob2VuaXgiLCJpYXQiOjE0NDg4Mzc1MTksImV4cCI6MTQ0OTA5NjcxOSwiYXVkIjoidG9rZW4ifQ.r7KYf6RzKhiPPRmhty-MwgMtBAtUU_JobVMWsp797pg"}, {"referer", "http://localhost:3000/"}, {"accept-encoding", "gzip, deflate, sdch"}, {"accept-language", "en-US,en;q=0.8"}], request_path: "/api/v1/current_user", resp_body: nil, resp_cookies: %{}, resp_headers: [{"access-control-allow-origin", "*"}, {"access-control-expose-headers", []}, {"access-control-allow-credentials", "true"}], scheme: :http, script_name: [], secret_key_base: "+/HZDLRRXtmKO5oN1n/vw35suQI/2iLJNr6sKhs8iDod8H0wWRYwPe5FNYZpOvQj", state: :unset, status: nil}, %{})
        (react_phoenix) web/controllers/v1/user_controller.ex:1: ReactPhoenix.V1.UserController.action/2
        (react_phoenix) web/controllers/v1/user_controller.ex:1: ReactPhoenix.V1.UserController.phoenix_controller_pipeline/2
        (react_phoenix) lib/phoenix/router.ex:255: ReactPhoenix.Router.dispatch/2
        (react_phoenix) web/router.ex:1: ReactPhoenix.Router.do_call/2
        (react_phoenix) lib/react_phoenix/endpoint.ex:1: ReactPhoenix.Endpoint.phoenix_pipeline/1
        (react_phoenix) lib/plug/debugger.ex:90: ReactPhoenix.Endpoint."call (overridable 3)"/2
        (react_phoenix) lib/phoenix/endpoint/render_errors.ex:34: ReactPhoenix.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
^C
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
^C%
ryanswapp commented 8 years ago

Looks like it was an issue with Redux. In one of the pull requests the author took out the bit of code that sent a JWT to the server as a param and it messed everything up. I just added it back and everything should be working!

brandonmikeska commented 8 years ago

I am still getting this error along with the style.css not being found. I just cloned it and started it up and I am getting these errors. Any ideas?

ryanswapp commented 8 years ago

@brandonmikeska I haven't added a dynamic index.html file yet so the style.css error will still pop up. In order to facilitate hot module reloading in development, webpack needs to combine the css into the bundle.js file and not into a separate css file so the index.html file is looking for a style.css file that doesn't exist. This results in an error being thrown. The styles still work though because webpack is pushing them into the javascript bundle. However, if you were to run webpack in production mode it would create a separate css file and the index.html file wouldn't complain. In order to fix this I just need to create a dynamic index.html file that removes the link to style.css in development and puts it back for production.

You're getting an error with authentication? Can you post the exact error code?

brandonmikeska commented 8 years ago

Oh ok my apologies about the style. I need to go learn webpack haha.

For the authentication error, I get the following error when starting up the application.

Failed to load resource: the server responded with a status of 401 (Unauthorized)

ryanswapp commented 8 years ago

@brandonmikeska Does the login feature work though? This error pops up when you go to the login page because Redux is checking to see if the user is logged in and the server responds with a 401. You should be able to login and the error will go away.

The template has some rough edges that I need to straighten out when I have some time. I'm currently in law school and have finals this week and next so I will be a bit busy until Christmas break hits. I'll definitely be ironing things out over the break. That said, everything should be working now so you should be able to get up and running.

brandonmikeska commented 8 years ago

Yes the log in works. Thank you for this template!