diff --git a/frontend/package.json b/frontend/package.json
index f6bd23ee..fd16c2d5 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -33,6 +33,7 @@
"vue-apexcharts": "^1.5.2",
"vue-clipboard2": "^0.3.1",
"vue-codemirror": "^4.0.6",
+ "vue-cookies": "^1.7.0",
"vue-flatpickr-component": "^8.1.5",
"vue-github-button": "^1.1.2",
"vue-moment": "^4.1.0",
diff --git a/frontend/src/API.js b/frontend/src/API.js
index 0ae562e2..e062a728 100644
--- a/frontend/src/API.js
+++ b/frontend/src/API.js
@@ -4,7 +4,7 @@ import * as Sentry from "@sentry/browser";
import * as Integrations from "@sentry/integrations";
const qs = require('querystring');
-const tokenKey = "statping_user";
+const tokenKey = "statping_auth";
const errorReporter = "https://bed4d75404924cb3a799e370733a1b64@sentry.statping.com/3"
class Api {
@@ -29,6 +29,10 @@ class Api {
return axios.post('api/core', obj).then(response => (response.data))
}
+ async oauth_save(obj) {
+ return axios.post('api/oauth', obj).then(response => (response.data))
+ }
+
async setup_save(data) {
return axios.post('api/setup', qs.stringify(data)).then(response => (response.data))
}
@@ -228,19 +232,11 @@ class Api {
async login(username, password) {
const f = {username: username, password: password}
- return axios.post('api/login', qs.stringify(f))
- .then(response => (response.data))
+ return axios.post('api/login', qs.stringify(f)).then(response => (response.data))
}
async logout() {
- await axios.get('api/logout').then(response => (response.data))
- return localStorage.removeItem(tokenKey)
- }
-
- saveToken(username, token, admin) {
- const user = {username: username, token: token, admin: admin}
- localStorage.setItem(tokenKey, JSON.stringify(user));
- return user
+ return axios.get('api/logout').then(response => (response.data))
}
async scss_base() {
@@ -255,17 +251,17 @@ class Api {
}
token() {
- const tk = localStorage.getItem(tokenKey)
+ const tk = $cookies.get(tokenKey)
if (!tk) {
- return {};
+ return {admin: false};
}
- return JSON.parse(tk);
+ return tk;
}
authToken() {
- let user = JSON.parse(localStorage.getItem(tokenKey));
- if (user && user.token) {
- return {'Authorization': 'Bearer ' + user.token};
+ const tk = $cookies.get(tokenKey)
+ if (tk.token) {
+ return {'Authorization': 'Bearer ' + tk.token};
} else {
return {};
}
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index c605d153..323a7651 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -32,22 +32,19 @@
this.$router.push('/setup')
}
if (this.$route.path !== '/setup') {
- if (this.core.logged_in) {
+ if (this.$store.state.admin) {
await this.$store.dispatch('loadAdmin')
} else {
await this.$store.dispatch('loadRequired')
}
this.loaded = true
}
-
-
},
async mounted() {
if (this.$route.path !== '/setup') {
- const tk = localStorage.getItem("statping_user")
- if (this.core.logged_in) {
+ if (this.$store.state.admin) {
this.logged_in = true
- await this.$store.dispatch('loadAdmin')
+ // await this.$store.dispatch('loadAdmin')
}
}
}
diff --git a/frontend/src/components/Dashboard/TopNav.vue b/frontend/src/components/Dashboard/TopNav.vue
index b87c360c..3bfa458a 100644
--- a/frontend/src/components/Dashboard/TopNav.vue
+++ b/frontend/src/components/Dashboard/TopNav.vue
@@ -28,7 +28,7 @@
- Logout
+ Logout
@@ -37,6 +37,7 @@