Browse Source

Add auth service to remove hard coded url from auth store

pull/341/head
Hironsan 5 years ago
parent
commit
4ac8eb0402
4 changed files with 16 additions and 7 deletions
  1. 1
      frontend/components/organisms/auth/LoginForm.vue
  2. 4
      frontend/services/api.service.js
  3. 13
      frontend/services/auth.service.js
  4. 5
      frontend/store/auth.js

1
frontend/components/organisms/auth/LoginForm.vue

@ -17,6 +17,7 @@
name="login"
prepend-icon="person"
type="text"
autofocus
/>
<v-text-field
id="password"

4
frontend/services/api.service.js

@ -16,10 +16,6 @@ class ApiService {
this.instance.defaults.headers.common = {}
}
neko() {
return this.instance
}
request(method, url, data = {}, config = {}) {
return this.instance({
method,

13
frontend/services/auth.service.js

@ -0,0 +1,13 @@
import ApiService from '@/services/api.service'
class AuthService {
constructor() {
this.request = ApiService
}
postCredential(data) {
return this.request.post(`/auth-token`, data)
}
}
export default new AuthService()

5
frontend/store/auth.js

@ -1,5 +1,6 @@
import Cookie from 'js-cookie'
import ApiService from '@/services/api.service'
import AuthService from '@/services/auth.service'
export const state = () => ({
token: null
@ -22,9 +23,7 @@ export const getters = {
export const actions = {
authenticateUser({ commit }, authData) {
const authUrl = 'http://127.0.0.1:8000/v1/auth-token'
return this.$axios
.$post(authUrl, authData)
return AuthService.postCredential(authData)
.then((result) => {
commit('setToken', result.token)
localStorage.setItem('token', result.token)

Loading…
Cancel
Save