diff options
author | Derick Montague <derick.montague@ibm.com> | 2019-12-05 01:30:08 +0300 |
---|---|---|
committer | Derick Montague <derick.montague@ibm.com> | 2020-01-23 02:44:50 +0300 |
commit | e080a1a7593e83a49d623ffdd452fd0e1c617889 (patch) | |
tree | bb94dee85cae80a3f54f4fbcf1d816f304129e67 /src/store/modules | |
parent | 186ce2e407812f417aba7a2ee2ab6cae5d5f3b0e (diff) | |
download | webui-vue-e080a1a7593e83a49d623ffdd452fd0e1c617889.tar.xz |
Add login and logout functionality
- Add AuthenticationStore
- Add ability to login and logout
- Add route navigation guard
- Add login styles
- Add temporary authentication for api call
- Add Login directory
- Add index.js
In order to login a .env.development.local file that contains
BASE_URL="https://<ip address> or <FQDN>"
Signed-off-by: Derick Montague <derick.montague@ibm.com>
Change-Id: I88b93e287e66f4bae82a1ec2934cdef12d78264e
Diffstat (limited to 'src/store/modules')
-rw-r--r-- | src/store/modules/Authentication/AuthenticanStore.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js new file mode 100644 index 00000000..828c3cc8 --- /dev/null +++ b/src/store/modules/Authentication/AuthenticanStore.js @@ -0,0 +1,56 @@ +import api from "../../api"; + +const AuthenticationStore = { + namespaced: true, + state: { + auth: {}, + status: "", + token: sessionStorage.getItem("token") || "" + }, + getters: { + authStatus: state => state.status, + isLoggedIn: state => !!state.token + }, + mutations: { + authRequest(state) { + state.status = "loading"; + }, + authSuccess(state, token, auth) { + state.status = "authenicated"; + state.auth = auth; + state.token = token; + }, + authError(state) { + state.status = "error"; + }, + logout(state) { + state.status = ""; + state.token = ""; + } + }, + actions: { + login({ commit }, auth) { + commit("authRequest"); + return api + .post("/login", auth) + .then(response => { + const token = response.data.token; + sessionStorage.setItem("token", token); + api.defaults.auth = auth; // TODO Permanent Solution + commit("authSuccess", token, auth); + }) + .catch(error => { + commit("authError"); + sessionStorage.removeItem("token"); + throw new Error(error); + }); + }, + logout({ commit }) { + commit("logout"); + sessionStorage.removeItem("token"); + api.defaults.auth = {}; // Permanent solution + } + } +}; + +export default AuthenticationStore; |