This file contains 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
// src/main.js | |
// ... | |
import configureAxios from './services/http'; | |
//... | |
configureAxios(); |
This file contains 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
// services/http.js | |
import axios from 'axios'; | |
import router from '@/router'; | |
import { store, mutations, actions } from '@/store'; | |
export default function configureAxios() { | |
axios.defaults.headers = { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', |
This file contains 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
<?php | |
namespace App\Providers; | |
// ... | |
class AuthServiceProvider extends ServiceProvider | |
{ | |
// ... | |
This file contains 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
// src/App.vue | |
<script> | |
import { actions } from '@/store'; | |
export default { | |
// ... | |
methods: { | |
// ... | |
logout() { |
This file contains 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
// src/store.js | |
// ... | |
export const actions = { | |
logout() { | |
store.accessToken = null; | |
window.localStorage.removeItem('accessToken'); | |
window.localStorage.removeItem('refreshToken'); | |
}, |
This file contains 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
// src/views/Home.vue | |
<script> | |
import axios from 'axios'; | |
import { store, getters } from '@/store'; | |
export default { | |
async mounted() { | |
if (this.isLoggedIn) { | |
try { |
This file contains 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
// src/App.vue | |
// src/views/Home.vue | |
<script> | |
// ... | |
import { getters } from '@/store'; | |
export default { | |
computed: { | |
isLoggedIn: () => getters.isLoggedIn(), |
This file contains 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
// src/views/OAuthCallbackHandler.vue | |
<script> | |
import axios from 'axios'; | |
import { mutations } from '@/store'; | |
export default { | |
async mounted() { | |
try { | |
const response = await axios.post('/oauth/token', { |
This file contains 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
// src/store.js | |
import Vue from 'vue'; | |
export const store = Vue.observable({ | |
accessToken: window.localStorage.getItem('accessToken'), | |
}); | |
export const getters = { | |
isLoggedIn() { |
This file contains 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
// src/views/OAuthCallbackHandler.vue | |
<script> | |
import axios from 'axios'; | |
export default { | |
async mounted() { | |
try { | |
const response = await axios.post(`${process.env.VUE_APP_OAUTH_AUTH_SERVER}/oauth/token`, { | |
grant_type: 'authorization_code', |