Skip to content

Instantly share code, notes, and snippets.

View blogui91's full-sized avatar
🎯
Focusing

Cesar Santana blogui91

🎯
Focusing
  • Doorvel
  • Monterrey
  • 09:31 (UTC -06:00)
View GitHub Profile
import OAuth from 'src/oauth'
import router from 'src/router'
let oAuth = new OAuth();
router.beforeEach((to,from,next) => {
//If visiting login view but you already have logged in, you should not be able to see this view
if (to.name == 'app.login' && oAuth.isAuthenticated()) {
return next({
<template>
<q-layout
ref="layout"
view="lHh Lpr fff"
:left-class="{'bg-grey-2': true}"
>
<q-toolbar slot="header" class="glossy">
<q-btn
flat
@click="$refs.layout.toggleLeft()"
import http from 'axios'
import OAuth from 'src/oauth'
let oAuth = new OAuth();
http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'
// Add a request interceptor
http.interceptors.request.use(function (config) {
config.headers['Authorization'] = oAuth.getAuthHeader() //Example: Bearer asf3132dfsfddffd
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
function load (component) {
// '@' is aliased to src/components
return () => import(`@/${component}.vue`)
}
<template>
<div class="login-view layout-padding">
<q-card class="bg-white card" inline>
<q-card-title>
<h3>Login</h3>
<span slot="subtitle"></span>
</q-card-title>
<q-card-main>
<form @submit.prevent="login">
<q-input v-model="form.username" stack-label="Email" />
@blogui91
blogui91 / api.routes.js
Last active September 10, 2017 21:45
We declare here all our routes for the application
import {
BASE_TOKEN,
API_URL,
} from 'config/auth'
export default {
TOKEN_URL: BASE_TOKEN + 'oauth/token',
CURRENT_USER_URL : API_URL + "users/user",
endpoints: {
@blogui91
blogui91 / oauth.service.js
Last active September 12, 2017 04:00
Service for OAuth class
import Http from 'axios'
import API from 'api/routes' // We create a file to store all the endpoints
export default {
user : null,
destroySession(){
this.user = null
},
async currentUser(){
if(this.user) {
return this.user
@blogui91
blogui91 / bootstrap-v2.index.js
Created September 10, 2017 15:19
Injecting OAuth as helper
import OAuth from 'oauth'
export default
{
install(Vue, options){
//In this way we'll expose our class in all Vue components
Vue.prototype.$oauth = new OAuth();
Vue.mixin({
mounted(){
@blogui91
blogui91 / oauth.index.js
Last active September 10, 2017 04:37
Class Auth
/***************************************************
* [Quasar Cookies] http://quasar-framework.org/components/cookies.html
* [Quasar LocalStorage] http://quasar-framework.org/components/web-storage.html
**************************************************/
import { Cookies, LocalStorage } from 'quasar'
import AuthService from './auth.service'
@blogui91
blogui91 / config.auth.js
Last active October 21, 2017 15:14
Settings for authetications
export const STATUS = 'local';
let secrets = {
API_LOCAL : 'mysecretinlocal',
API_DEV : 'mysecretindev',
API_PRODUCTION : 'mysecretinproduction'
}
export const BASE_URL = {
'local' : 'http://localhost:8000/',