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
require_relative 'boot' | |
require "rails" | |
require "active_model/railtie" | |
require "active_job/railtie" | |
require "active_record/railtie" | |
require "active_storage/engine" | |
require "action_controller/railtie" | |
require "action_mailer/railtie" | |
require "action_mailbox/engine" |
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::API | |
include ActionController::Cookies | |
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, debug: true do | |
allow do | |
origins 'http://client.your-domain-here.ngrok.io' | |
resource '*', | |
headers: :any, | |
methods: [:get, :post, :put, :patch, :delete, :options, :head] | |
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
module CoreModules::JsonWebToken | |
require 'jwt' | |
JWT_SECRET = Rails.application.secrets.secret_key_base | |
def self.encode(payload, exp = 24.hours.from_now) | |
payload[:exp] = exp.to_i | |
JWT.encode(payload, JWT_SECRET) | |
end | |
def self.decode(token) |
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
require_relative 'boot' | |
require "rails" | |
require "active_model/railtie" | |
require "active_job/railtie" | |
require "active_record/railtie" | |
require "active_storage/engine" | |
require "action_controller/railtie" | |
require "action_mailer/railtie" |
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::API | |
include ActionController::Cookies | |
def authenticate_cookie | |
token = cookies.signed[:jwt] | |
decoded_token = CoreModules::JsonWebToken.decode(token) | |
if decoded_token | |
user = User.find_by(id: decoded_token["user_id"]) | |
end | |
if user then return true else render json: {status: 'unauthorized', code: 401} 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 Api::V1::SessionsController < ApplicationController | |
before_action only: [:destroy] do | |
authenticate_cookie | |
end | |
def destroy | |
user = current_user | |
if user | |
cookies.delete(:jwt) | |
render json: {status: 'OK', code: 200} |
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
export const login = (email, password) => { | |
return new Promise((resolve, reject) => { | |
let endpoint = `http://api.your-domain-here.ngrok.io/api/core/v1/sessions`; | |
fetch(endpoint, { | |
method: "POST", | |
credentials: "include", | |
headers: { | |
"Content-Type": "application/json", | |
"Accept": "application/json", | |
}, |
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
## METHOD 1 - using nmap | |
# get local ip | |
ifconfig |grep inet | |
# scan for devices on local network | |
sudo nmap -sP 192.xxx.y.zz/24 | |
# when pi ip is shown connect with the user name | |
ssh [email protected] | |
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
#tunnel requests that hit api.your-subdomain.ngrok.io to http://localhost:5500 | |
./ngrok http 5500 -subdomain api.your-subdomain |
OlderNewer