Skip to content

Commit

Permalink
Merge pull request #2625 from semaphoreui/httponly
Browse files Browse the repository at this point in the history
feat(auth): httponly
  • Loading branch information
fiftin authored Dec 13, 2024
2 parents 5e88746 + 07fcaba commit 9df76e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
29 changes: 13 additions & 16 deletions web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,6 @@ export default {
return this.projects.find((x) => x.id === this.projectId);
},
isAuthenticated() {
return document.cookie.includes('semaphore=');
},
templatesUrl() {
let viewId = localStorage.getItem(`project${this.projectId}__lastVisitedViewId`);
if (viewId) {
Expand All @@ -911,14 +907,6 @@ export default {
},
async created() {
if (!this.isAuthenticated) {
if (this.$route.path !== '/auth/login') {
await this.$router.push({ path: '/auth/login' });
}
this.state = 'success';
return;
}
if (localStorage.getItem('darkMode') === '1') {
this.darkMode = true;
}
Expand All @@ -927,6 +915,14 @@ export default {
await this.loadData();
this.state = 'success';
} catch (err) {
if (err.response && err.response.status === 401) {
if (this.$route.path !== '/auth/login') {
await this.$router.push({ path: '/auth/login' });
}
this.state = 'success';
return;
}
EventBus.$emit('i-snackbar', {
color: 'error',
text: getErrorMessage(err),
Expand Down Expand Up @@ -1063,6 +1059,11 @@ export default {
},
methods: {
async isAuthenticated() {
return document.cookie.includes('semaphore=');
},
async onSubscriptionKeyUpdates() {
EventBus.$emit('i-snackbar', {
color: 'success',
Expand Down Expand Up @@ -1158,10 +1159,6 @@ export default {
},
async loadUserInfo() {
if (!this.isAuthenticated) {
return;
}
this.user = (await axios({
method: 'get',
url: '/api/user',
Expand Down
20 changes: 17 additions & 3 deletions web/src/views/Auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ export default {
},
async created() {
if (this.isAuthenticated()) {
if (await this.isAuthenticated()) {
document.location = document.baseURI;
return;
}
await axios({
method: 'get',
Expand All @@ -207,8 +208,21 @@ export default {
return pwd;
},
isAuthenticated() {
return document.cookie.includes('semaphore=');
async isAuthenticated() {
try {
await axios({
method: 'get',
url: '/api/user',
responseType: 'json',
});
} catch (err) {
if (err.response.status === 401) {
return false;
}
throw err;
}
return true;
},
async signIn() {
Expand Down

0 comments on commit 9df76e6

Please sign in to comment.