Skip to content

Instantly share code, notes, and snippets.

View whiz25's full-sized avatar

Afani Martin whiz25

View GitHub Profile
@whiz25
whiz25 / .rb
Last active January 14, 2020 09:45
session store configuration
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
@whiz25
whiz25 / cors.rb
Last active January 14, 2020 10:02
cors configuration
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
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,
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])
class StaticController < ApplicationController
def home
render json: {status: "It's working..."}
end
end
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
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
class ApplicationController < ActionController::Base
skip_before_action :verify_authenticity_token
end
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: "",
@whiz25
whiz25 / login.js
Last active January 14, 2020 18:31
import React, { Component } from "react";
import axios from "axios";
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
email: "",
password: "",