ynnadkrap / balldontlie

NBA API
http://www.balldontlie.io
223 stars 19 forks source link

Login/Home page #9

Open ynnadkrap opened 5 years ago

ynnadkrap commented 5 years ago

In order to create a more serviceable website with user accounts and UI interactions, we need a home page that allows users to login or register.

I want to use react on the frontend. Even though it's overkill for this feature, it'll be a good foundation to build on in the event we want to build out more features. Let's use create-react-app with typescript (https://facebook.github.io/create-react-app/docs/adding-typescript) enabled. I don't think we need to use devise for auth — we can hand-roll something super simple (use has_secure_password for user model https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html). Since rails is in API mode, we'll need to include sessions and cookies:

class Application < Rails::Application
  config.load_defaults 5.2

  config.api_only = true

  config.middleware.use ActionDispatch::Cookies
  config.middleware.use ActionDispatch::Session::CookieStore
end

class ApplicationController < ActionController::API
  include ActionController::Cookies
  include ActionController::RequestForgeryProtection

  protect_from_forgery with: :exception

  ...

end

Since this will be a single page app, we can make a request to an endpoint on the initial render that checks to see if the user is logged in.