Created
September 27, 2019 06:54
-
-
Save sayhicoelho/42266b739c8b30782d4d074362b8fd0a to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | |
<title>example-app</title> | |
<style> | |
html, | |
body { | |
height: 100%; | |
} | |
.centered { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- NOTE: The 'centered' class will be removed after new Vue(...) --> | |
<div id="app" class="centered"> | |
<img src="/static/loader.svg" alt="Loading..."> | |
</div> | |
<!-- built files will be auto injected --> | |
</body> | |
</html> |
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
// The Vue build version to load with the `import` command | |
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. | |
import Vue from 'vue' | |
import App from './App' | |
import store from './store' | |
Vue.config.productionTip = false | |
function checkAuth() { | |
return new Promise(resolve => { | |
// We're getting the current user from localStorage | |
const user = window.localStorage.getItem('user') | |
if (user) { | |
// We're simulating the request | |
setTimeout(() => { | |
store.replaceState({ currentUser: JSON.parse(user) }) | |
resolve() | |
}, 1000) | |
} else { | |
resolve() | |
} | |
}) | |
} | |
function createApp() { | |
/* eslint-disable no-new */ | |
new Vue({ | |
el: '#app', | |
store, | |
components: { App }, | |
template: '<App/>' | |
}) | |
} | |
checkAuth() | |
.then(createApp) |
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 Vue from 'vue' | |
import Vuex from 'vuex' | |
Vue.use(Vuex) | |
export default new Vuex.Store({ | |
state: { | |
currentUser: null | |
}, | |
mutations: { | |
SET_AUTH(state, user) { | |
window.localStorage.setItem('user', JSON.stringify(user)) | |
state.currentUser = user | |
}, | |
REMOVE_AUTH(state) { | |
window.localStorage.removeItem('user') | |
state.currentUser = null | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment