Code Monkey home page Code Monkey logo

phoenix_token_auth_react's Introduction

PhoenixTokenAuthReact

This is an example app using Phoenix, phoenix_token_auth and React.

Branch master uses phoenix_token_auth's latest hex release and branch development might use a more current version of phoenix_token_auth's master branch.

You need to have a (free) mailgun account to be able to send welcome emails. You'll need to know your mailgun domain, and HTTP API key.

Running

  • Clone the repository and change into it's directory
  • Install dependencies:
mix deps.get && npm install
  • Create and migrate the database (You might also need to change the DB username/password in config/dev.exs before you try to run the DB creation and migration tasks.)
mix do ecto.create, ecto.migrate
  • Add some example data
mix seed_db
  • Configure a real mail user, in the same domain as the mailgun domain you configured, in config/config.exs.
    config :phoenix_token_auth,
      ...
      email_sender: "[email protected]",
      ...
  • Start the server
MAILGUN_DOMAIN=... MAILGUN_KEY=... mix phoenix.server

Testing

In order to run mix test, which makes use of Hound for testing, you need a local webdriver server to be running. You can find simple instructions at https://github.com/HashNuke/hound/wiki/Starting-a-webdriver-server

On OS X with Firefox and Homebrew installed you may install the Selenium web driver and follow the instructions for running it:

brew install selenium-server-standalone

You may also need to change the DB username/password in config/test.exs before you try to run the tests.

Credits

A lot of inspiration and code were taken from https://github.com/FancyPixel/small-frontend.

phoenix_token_auth_react's People

Contributors

grempe avatar manukall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

phoenix_token_auth_react's Issues

Trying to login: undefined function: Timex.Date.now/0 (module Timex.Date is not available)

When I try to login via the ReactJS login page, I get the following error:

[info] POST /api/v1/sessions
[info] Processing by PhoenixTokenAuth.SessionsController.create/2
  Parameters: %{"email" => "[email protected]", "format" => "json", "password" => "[FILTERED]"}
  Pipelines: [:api]
[debug] SELECT u0."id", u0."email", u0."hashed_password", u0."hashed_confirmation_token", u0."confirmed_at", u0."hashed_password_reset_token", u0."unconfirmed_email", u0."authentication_tokens", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."email" = $1) ["[email protected]"] (106.6ms)
[info] Sent 500 in 934ms
[error] #PID<0.288.0> running PhoenixTokenAuthReact.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /api/v1/sessions
** (exit) an exception was raised:
    ** (UndefinedFunctionError) undefined function: Timex.Date.now/0 (module Timex.Date is not available)
        Timex.Date.now()
        lib/phoenix_token_auth/authenticator.ex:59: PhoenixTokenAuth.Authenticator.token_expiry_secs/0
        lib/phoenix_token_auth/authenticator.ex:48: PhoenixTokenAuth.Authenticator.generate_unique_token_for/1
        lib/phoenix_token_auth/authenticator.ex:42: PhoenixTokenAuth.Authenticator.generate_token_for/1
        lib/phoenix_token_auth/authenticator.ex:18: PhoenixTokenAuth.Authenticator.authenticate/2
        lib/phoenix_token_auth/sessions_controller.ex:19: PhoenixTokenAuth.SessionsController.create/2
        lib/phoenix_token_auth/sessions_controller.ex:1: PhoenixTokenAuth.SessionsController.phoenix_controller_pipeline/2
        (phoenix_token_auth_react) lib/phoenix/router.ex:297: PhoenixTokenAuthReact.Router.dispatch/2

README should indicate need to change email_sender config value

On a new clone I was unable to send emails until I found and also changed the config value in config/config.exs from :

email_sender: "[email protected]"

to something appropriate for my domain. Until I did so I would see this in the logs, indicating apparent success, but mailgun would apparently not actually deliver it:

[info] Sent welcome email to SOME_EMAIL

Also, the README should make clear that the Elixir mailgun client is using the mailgun HTTP API, not the SMTP server, so the credentials used should reflect that. Those coming from Rails, used to sending mail via SMTP, might be tripped up by this.

Thanks for the great example code.

Error if I visit the "Confirmation Link" for an account that has already been confirmed.

Here's the error I get:

 localhost:4000 (http)
Request: POST /api/v1/users/45/confirm
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in PhoenixTokenAuth.Confirmator.confirmation_changeset/2
        lib/phoenix_token_auth/confirmator.ex:31: PhoenixTokenAuth.Confirmator.confirmation_changeset(%CallRedApp.User{__meta__: %Ecto.Schema.Metadata{source: {nil, "users"}, state: :loaded}, authentication_tokens: ["eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl9pZCI6ImttV2wyWXkvcTBjaHNtVlV6WENOTVhsMEVlVHpQbUFRIiwiaWQiOjQ1LCJleHAiOjE0Mzk2ODk5NTN9.OXIeHuFLgz3YMGJmmiHocbiHhY2ryOVmuZ4ECLr1NLk", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl9pZCI6IkZvVWJ6OUx5VUMzc3FXaERDU25pblVTb2VZd21qM3BqIiwiaWQiOjQ1LCJleHAiOjE0Mzk2ODg3NDh9.A3o32ObKIgNQaX4aaCKocGQlV6mSYFlNMbnCNo_oNm4", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl9pZCI6IkMvVXF3K20ra3BQcExXQndDWW1xbmlpMmJQS29oQWZtIiwiaWQiOjQ1LCJleHAiOjE0Mzk2ODg3MTl9.O_W-07Bjz02FE0m8OwpPcavNRl0iS_zFV957yw_xWdM"], confirmed_at: %Ecto.DateTime{day: 9, hour: 1, min: 31, month: 8, sec: 59, usec: 0, year: 2015}, email: "[email protected]", first_name: nil, hashed_confirmation_token: nil, hashed_password: "$2b$12$vJvB1UizlIa3W4sGUmmObe2s2xOxKohecKhgWo9aUKFtri6zkMrr.", hashed_password_reset_token: nil, id: 45, inserted_at: %Ecto.DateTime{day: 9, hour: 0, min: 37, month: 8, sec: 5, usec: 0, year: 2015}, last_name: nil, messages: #Ecto.Association.NotLoaded<association :messages is not loaded>, phone_number: nil, state: nil, superadmin: false, unconfirmed_email: nil, updated_at: %Ecto.DateTime{day: 9, hour: 1, min: 52, month: 8, sec: 33, usec: 0, year: 2015}}, %{"confirmation_token" => "SxUR7vHzw4fc271nUYxre8n3d9CP97YRxdJbmueMNInxFfRS_yQ86yYxYJzFBTyDGdHytMphpN7XU3MiM3LODQ", "format" => "json", "id" => "45"})
        lib/phoenix_token_auth/controllers/users_controller.ex:70: PhoenixTokenAuth.Controllers.Users.confirm/2
        lib/phoenix_token_auth/controllers/users_controller.ex:1: PhoenixTokenAuth.Controllers.Users.phoenix_controller_pipeline/2

Password Reset

When resetting your password, the screen does not change and I'm not getting the email. However, I did get the initial confirmation email when the account was created.

JS # in routing / URL

Any chance you could have the routes remove the # in the URL and have it work for page refreshes?

Using with MySQL

Hi,

I'd like to use this library with MySQL, but MySQL doesn't support arrays. Would it kill the library if I changed the authentication_tokens column to a string? Ideally, I guess, this should be a lookup table. Thoughts?

Thanks,
Lee

PhoenixTokenAuthReact.Endpoint terminated

[error] #PID<0.379.0> running PhoenixTokenAuthReact.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /api/v1/users
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: {:error, 401, "Forbidden"}
lib/phoenix_token_auth/mailer.ex:33: PhoenixTokenAuth.Mailer.send_welcome_email/2
lib/ecto/adapters/sql.ex:442: Ecto.Adapters.SQL.transaction/3
lib/phoenix_token_auth/users_controller.ex:29: PhoenixTokenAuth.UsersController.create/2
lib/phoenix_token_auth/users_controller.ex:1: PhoenixTokenAuth.UsersController.phoenix_controller_pipeline/2
(phoenix_token_auth_react) lib/phoenix/router.ex:297: PhoenixTokenAuthReact.Router.dispatch/2
(phoenix_token_auth_react) lib/phoenix/router.ex:2: PhoenixTokenAuthReact.Router.call/2
(phoenix_token_auth_react) lib/phoenix_token_auth_react/endpoint.ex:1: PhoenixTokenAuthReact.Endpoint.phoenix_endpoint_pipeline/1
(phoenix_token_auth_react) lib/plug/debugger.ex:90: PhoenixTokenAuthReact.Endpoint."call (overridable 3)"/2

New Poison dependency version for phoenix_token_auth prevents upgrade of this demo to Phoenix 0.13.0

I am doing a version by version upgrade of this demo app to Phoenix 0.13.0 (which I am submitting in pull requests to you soon) but I can't do the upgrade from 0.12.0 to 0.13.0. The problem is that you bumped the version requirement for Poison to ~> 1.4.0 and both hound and mailgun which are required for this app need ~> 1.3.0.

~/src/phoenix_token_auth_react (master โœ—)$ mix deps.get
Running dependency resolution
Looking up alternatives for conflicting requirements on poison
  Activated version: 1.3.1
  From phoenix_token_auth v0.0.8: ~> 1.4.0
  From hound v0.6.0: ~> 1.3.0
  From deps/mailgun/mix.exs: ~> 1.3.1
** (Mix) Hex dependency resolution failed, relax the version requirements or unlock dependencies

You seem to have upgraded the version requirement in the other repository in this commit: 022193c8f16e8842c875be17ec88701dc3ea26d5

Its not clear to me on a quick look why. Can you see about relaxing the new requirement to allow >= 1.3.0 and pushing a new version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.