Skip to content

Instantly share code, notes, and snippets.

View ashishwadekar's full-sized avatar

Ashish Wadekar ashishwadekar

  • India
View GitHub Profile
@ashishwadekar
ashishwadekar / vue-apollo.js
Created February 25, 2019 16:43
Apollo Configuration
import Vue from 'vue'
import VueApollo from 'vue-apollo'
import {
createApolloClient,
restartWebsockets
} from 'vue-cli-plugin-apollo/graphql-client'
// Install the vue plugin
Vue.use(VueApollo)
@ashishwadekar
ashishwadekar / fontawesome.vue
Last active January 18, 2019 09:52 — forked from Ethanhackett/fontawesome.vue
Font Awesome 5 Pro - Vue.js + Native Script Component
<template>
<Span v-bind:class="classes + ' ' + type" v-bind:text="getIcon()" />
</template>
<script>
/*
Setup:
1. Setup CSS and Font in Native Script App like this:
https://medium.com/@JCAguilera/fontawesome-5-and-nativescript-22653f2b3bac
Thanks > Juanky Aguilera
@ashishwadekar
ashishwadekar / application_controller.rb
Created December 24, 2018 19:17
Sample application controller for Devise JWT
class ApplicationController < ActionController::API
include ActionController::MimeResponds
respond_to :json
end
@ashishwadekar
ashishwadekar / cors.rb
Created December 24, 2018 19:08
Sample CORS for Devise JWT
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: %w(Authorization),
methods: :any,
expose: %w(Authorization),
max_age: 600
end
end
@ashishwadekar
ashishwadekar / routes.rb
Created December 24, 2018 19:00
Routes setup for Devise JWT
Rails.application.routes.draw do
devise_for :users,
path: '',
path_names: {
sign_in: 'login',
sign_out: 'logout'
},
controllers: {
sessions: 'sessions',
@ashishwadekar
ashishwadekar / sessions_controller.rb
Created December 24, 2018 18:57
Sample sessions controller for Devise JWT
class SessionsController < Devise::SessionsController
respond_to :json
private
def respond_with(resource, _opts = {})
render json: resource
end
def respond_to_on_destroy
@ashishwadekar
ashishwadekar / devise.rb
Created December 24, 2018 18:43
JWT configuration for Devise : Login / Logout Endpoints
Devise.setup do |config|
# Add this at the end of the config block
config.jwt do |jwt|
jwt.secret = ENV['DEVISE_JWT_SECRET']
jwt.dispatch_requests = [
['POST', %r{^/login$}]
]
jwt.revocation_requests = [
['DELETE', %r{^/logout$}]
@ashishwadekar
ashishwadekar / jwt_blacklist.rb
Created December 24, 2018 18:26
Sample JWT Blacklist model
class JwtBlacklist < ApplicationRecord
include Devise::JWT::RevocationStrategies::Blacklist
self.table_name = 'jwt_blacklist'
end
@ashishwadekar
ashishwadekar / user.rb
Created December 24, 2018 18:25
Sample User model for JWT with revocation strategy
class User < ApplicationRecord
devise :database_authenticatable, :jwt_authenticatable,
jwt_revocation_strategy: JwtBlacklist
end
@ashishwadekar
ashishwadekar / create_jwt_blacklist_table_migration.rb
Created December 24, 2018 18:20
Sample migration file to create JWT
class CreateJwtBlacklists < ActiveRecord::Migration[5.2]
def change
create_table :jwt_blacklist do |t|
t.string :jti, null: false
t.datetime :exp, null: false
end
add_index :jwt_blacklist, :jti
end
end