This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if Rails.env == "production" | |
| Rails.application.config.session_store :cookie_store, key: "_authentication_app", domain: "https://link-to-your-production-app.com/" | |
| else | |
| Rails.application.config.session_store :cookie_store, key: "_authentication_app" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.config.middleware.insert_before 0, Rack::Cors do | |
| allow do | |
| origins "http://localhost:3000" | |
| resource "*", headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head], credentials: true | |
| end | |
| allow do | |
| origins "https://link-to-production-app.com/" | |
| resource "*", headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head], credentials: true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SessionsController < ApplicationController | |
| include CurrentUserConcern | |
| def create | |
| user = User.find_by(email: params["user"]["email"]).try(:authenticate, params["user"]["password"]) | |
| if user | |
| session[:user_id] = user.id | |
| render json: { | |
| status: :created, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module CurrentUserConcern | |
| extend ActiveSupport::Concern | |
| included do | |
| before_action :set_current_user | |
| end | |
| def set_current_user | |
| if session[:user_id] | |
| @current_user = User.find(session[:user_id]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class StaticController < ApplicationController | |
| def home | |
| render json: {status: "It's working..."} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.routes.draw do | |
| resources :sessions, only: [:create] | |
| resources :users | |
| delete :logout, to: "sessions#logout" | |
| get :logged_in, to: "sessions#logged_in" | |
| root to: "static#home" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RegistrationsController < ApplicationController | |
| def create | |
| user = User.create!( | |
| email: params["user"]["email"], | |
| password: params["user"]["password"], | |
| password_confirmation: params["user"]["password_confirmation"] | |
| ) | |
| if user | |
| session[:user_id] = user.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| skip_before_action :verify_authenticity_token | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from "react"; | |
| import axios from "axios"; | |
| import { Link } from "react-router-dom"; | |
| export default class Registration extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| email: "", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from "react"; | |
| import axios from "axios"; | |
| export default class Login extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| email: "", | |
| password: "", |
OlderNewer