inital commit
This commit is contained in:
105
resources/js/store/auth/actions.js
vendored
Normal file
105
resources/js/store/auth/actions.js
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
import axiosClient from '@/config/axios'
|
||||
import { removeToken, isApiSuccess, setToken, setRefreshToken, getRefreshToken } from '@/helper'
|
||||
|
||||
|
||||
export const login = ({ commit }, formData) => {
|
||||
return axiosClient
|
||||
.post('login', formData)
|
||||
.then(response => {
|
||||
|
||||
if (isApiSuccess(response)) {
|
||||
commit('SET_USER', response.data.user)
|
||||
commit('SET_AUTHENTICATED', false)
|
||||
}
|
||||
|
||||
return Promise.resolve(response)
|
||||
}).catch(exception => {
|
||||
commit('SET_USER', {})
|
||||
commit('SET_AUTHENTICATED', false)
|
||||
console.log('Login Action Exception', exception);
|
||||
})
|
||||
}
|
||||
|
||||
export const verifyOTP = ({ commit }, formData) => {
|
||||
return axiosClient.post('verifysms', formData)
|
||||
.then(response => {
|
||||
|
||||
if (isApiSuccess(response)) {
|
||||
commit('SET_AUTHENTICATED', true)
|
||||
|
||||
setToken(response.data.access_token)
|
||||
setRefreshToken(response.data.refresh_token)
|
||||
}
|
||||
|
||||
return Promise.resolve(response)
|
||||
}).catch(exception => {
|
||||
console.log('verifyOTP Action Exception', exception);
|
||||
})
|
||||
}
|
||||
|
||||
export const authenticateWithRefreshToken = ({ commit }) => {
|
||||
return axiosClient.post('refreshtoken', { refresh_token: getRefreshToken() })
|
||||
.then(response => {
|
||||
|
||||
if (isApiSuccess(response)) {
|
||||
commit('SET_AUTHENTICATED', true)
|
||||
|
||||
setToken(response.data.access_token)
|
||||
setRefreshToken(response.data.refresh_token)
|
||||
}
|
||||
|
||||
return Promise.resolve(response)
|
||||
}).catch(exception => {
|
||||
console.log('authenticateWithRefreshToken Action Exception', exception);
|
||||
})
|
||||
}
|
||||
|
||||
export const resendOTP = ({ commit }, formData) => {
|
||||
return axiosClient.post('resendotp', formData)
|
||||
.then(response => {
|
||||
return Promise.resolve(response)
|
||||
}).catch(exception => {
|
||||
console.log('Login Action Exception', exception);
|
||||
})
|
||||
}
|
||||
|
||||
export const authUser = ({ commit }) => {
|
||||
return axiosClient.get('get-authinfo')
|
||||
.then(response => {
|
||||
commit('SET_AUTHENTICATED', true)
|
||||
commit('SET_USER', response.data.user)
|
||||
commit('SET_PERMISSIONS', response.data.permissions)
|
||||
return Promise.resolve(response)
|
||||
}).catch(exception => {
|
||||
console.log('Get Auth User Action Exception', exception);
|
||||
})
|
||||
}
|
||||
|
||||
export const logout = ({ commit }) => {
|
||||
commit('SET_USER', {})
|
||||
commit('SET_AUTHENTICATED', false)
|
||||
removeToken()
|
||||
}
|
||||
|
||||
export const setLoader = ({ commit }, status) => {
|
||||
commit('SET_LOADER', status)
|
||||
}
|
||||
|
||||
export const loadPermissions = ({ commit }) => {
|
||||
return axiosClient
|
||||
.get('getpermission')
|
||||
.then(response => {
|
||||
commit('SET_PERMISSIONS', response.data.permissions)
|
||||
return Promise.resolve(response)
|
||||
}).catch(exception => {
|
||||
console.log('Permissions API Exception', exception);
|
||||
})
|
||||
}
|
||||
|
||||
export const isModalShow = ({ commit }, status) => {
|
||||
commit('SHOW_MODAL', status)
|
||||
}
|
||||
|
||||
export const userFormData = ({ commit }, value) => {
|
||||
commit('SET_USER_FORM_DATA', value)
|
||||
}
|
||||
22
resources/js/store/auth/getters.js
vendored
Normal file
22
resources/js/store/auth/getters.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export const authenticated = (state) => {
|
||||
return state.authenticated
|
||||
}
|
||||
|
||||
export const user = (state) => {
|
||||
return state.user
|
||||
}
|
||||
|
||||
export const getLoaderStatus = (state) => {
|
||||
return state.loader;
|
||||
}
|
||||
|
||||
export const getPermissions = (state) => {
|
||||
return state.permissions;
|
||||
}
|
||||
|
||||
export const getModalShowStatus = (state) => {
|
||||
return state.isModalShow;
|
||||
}
|
||||
export const getUserFormData = (state) => {
|
||||
return state.userFormData;
|
||||
}
|
||||
12
resources/js/store/auth/index.js
vendored
Normal file
12
resources/js/store/auth/index.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import state from "./state";
|
||||
import * as getters from "./getters";
|
||||
import * as mutations from "./mutations";
|
||||
import * as actions from "./actions";
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
22
resources/js/store/auth/mutations.js
vendored
Normal file
22
resources/js/store/auth/mutations.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export const SET_AUTHENTICATED = (state, value) => {
|
||||
state.authenticated = value
|
||||
}
|
||||
export const SET_USER = (state, value) => {
|
||||
state.user = value
|
||||
}
|
||||
|
||||
export const SET_LOADER = (state, value) => {
|
||||
state.loader = value
|
||||
}
|
||||
|
||||
export const SET_PERMISSIONS = (state, value) => {
|
||||
state.permissions = value
|
||||
}
|
||||
|
||||
export const SHOW_MODAL = (state, value) => {
|
||||
state.isModalShow = value
|
||||
}
|
||||
|
||||
export const SET_USER_FORM_DATA = (state, value) => {
|
||||
state.userFormData = value
|
||||
}
|
||||
8
resources/js/store/auth/state.js
vendored
Normal file
8
resources/js/store/auth/state.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export default {
|
||||
authenticated: false,
|
||||
user: {},
|
||||
permissions: {},
|
||||
loader: false,
|
||||
isModalShow: false,
|
||||
userFormData: {}
|
||||
}
|
||||
Reference in New Issue
Block a user