Skip to content

Commit

Permalink
Remove semicolons, style fixies
Browse files Browse the repository at this point in the history
  • Loading branch information
Dual-Ice committed May 21, 2020
1 parent 552ee80 commit 1d63884
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/admin/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
nav.nav-container
router-view(name="nav")
main.content-container
router-view
keep-alive
router-view

</template>
<script>
Expand Down
8 changes: 4 additions & 4 deletions src/admin/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
).login__send-data Отправить
</template>
<script>
import Icon from './Icon'
import Icon from './partial/Icon'
import axios from '../customAxios'
import CustomInput from './CustomInput'
import CustomInput from './partial/CustomInput'
import { required, minLength } from 'vuelidate/lib/validators'
export default {
Expand Down Expand Up @@ -66,8 +66,8 @@ export default {
try {
const response = await axios.post('/login', this.user)
const token = response.data.token
localStorage.setItem('user-token', token);
await this.$router.replace('/');
localStorage.setItem('user-token', token)
await this.$router.replace('/')
} catch (error) {
console.log(error)
}
Expand Down
22 changes: 11 additions & 11 deletions src/admin/customAxios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import axios from 'axios'

axios.defaults.baseURL = 'https://webdev-api.loftschool.com/';
axios.defaults.baseURL = 'https://webdev-api.loftschool.com/'
const token = localStorage.getItem('user-token')
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`
Expand All @@ -9,23 +9,23 @@ if (token) {
axios.interceptors.response.use(
response => (response),
error => {
const originRequest = error.config;
const originRequest = error.config

if (error.response.status === 401) {
return axios.post("/refreshToken")
.then(response => {
const token = response.data.token;
const token = response.data.token

localStorage.setItem('user-token', token);
axios.defaults.headers["Authorization"] = `Bearer ${token}`;
originRequest.headers["Authorization"] = `Bearer ${token}`;
localStorage.setItem('user-token', token)
axios.defaults.headers["Authorization"] = `Bearer ${token}`
originRequest.headers["Authorization"] = `Bearer ${token}`

return axios(originRequest);
return axios(originRequest)
})
}

return Promise.reject(error);
return Promise.reject(error)
}
);
)

export default axios;
export default axios
6 changes: 3 additions & 3 deletions src/admin/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Vue from 'vue';
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Vuelidate from 'vuelidate'
import axios from './customAxios'
import store from "./store";
import store from "./store"

Vue.use(Vuelidate)
Vue.axios = axios
Expand All @@ -13,4 +13,4 @@ new Vue({
render: h => h(App),
store,
router
});
})
22 changes: 11 additions & 11 deletions src/admin/router/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Vue from 'vue';
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import axios from '../customAxios'
Expand All @@ -11,23 +11,23 @@ const router = new VueRouter({
})

router.beforeEach(async (to, from, next) => {
const isAuthRequired = to.matched.some(record => record.meta.auth);
const isUserLogged = store.getters["auth/isLogged"];
const isAuthRequired = to.matched.some(record => record.meta.auth)
const isUserLogged = store.getters["auth/isLogged"]

if (isAuthRequired && !isUserLogged) {
const token = localStorage.getItem('user-token');
axios.defaults.headers['Authorization'] = `Bearer ${ token }`;
const token = localStorage.getItem('user-token')
axios.defaults.headers['Authorization'] = `Bearer ${ token }`

try {
const response = await axios.get('/user');
store.commit("auth/setUser", response.data.user);
next();
const response = await axios.get('/user')
store.commit("auth/setUser", response.data.user)
next()
} catch (e) {
await router.replace('/login');
localStorage.removeItem('user-token');
await router.replace('/login')
localStorage.removeItem('user-token')
}
} else {
next();
next()
}
document.title = to.meta.title || ''
})
Expand Down
4 changes: 2 additions & 2 deletions src/admin/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import auth from './modules/auth'
import works from './modules/works'
import reviews from './modules/reviews'
import categories from './modules/categories'
Vue.use(Vuex);
Vue.use(Vuex)

export default new Vuex.Store({
modules: {
Expand All @@ -13,4 +13,4 @@ export default new Vuex.Store({
reviews,
categories
}
});
})
2 changes: 1 addition & 1 deletion src/admin/store/modules/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
},

actions: {
async logoutUser ({ state, commit }) {
async logoutUser ({ commit }) {
await axios.post('/logout')
commit('setUser', {})
localStorage.removeItem('user-token')
Expand Down
8 changes: 4 additions & 4 deletions src/admin/utils/formData.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default (payload) => {
export default (data) => {
const formData = new FormData()

Object.keys(payload).forEach(key => {
formData.append(key, payload[key])
Object.keys(data).forEach(key => {
formData.append(key, data[key])
})

return formData;
return formData
}

0 comments on commit 1d63884

Please sign in to comment.