Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Remove httponly token cookie on user logout

天舟eb76b63e6db7
diff --git a/frontend/src/components/BookmarkListSidePanel.vue b/frontend/src/components/BookmarkListSidePanel.vue
index d06df7d8ec..86c665e182 100644
--- a/frontend/src/components/BookmarkListSidePanel.vue
+++ b/frontend/src/components/BookmarkListSidePanel.vue
@@ -17,6 +17,7 @@
import { computed, watchEffect } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
+import { UNKNOWN_ID } from "../types";
export default {
name: "BookmarkListSidePanel",
@@ -27,7 +28,13 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
const prepareBookmarkList = () => {
- store.dispatch("bookmark/fetchBookmarkListByUser", currentUser.value.id);
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store.dispatch(
+ "bookmark/fetchBookmarkListByUser",
+ currentUser.value.id
+ );
+ }
};
watchEffect(prepareBookmarkList);
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index 2fef0bb8c7..26bb97e4c5 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -12,7 +12,7 @@ import { computed, watchEffect } from "vue";
import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
-import { Database, Environment, EnvironmentId } from "../types";
+import { Database, Environment, EnvironmentId, UNKNOWN_ID } from "../types";
import { databaseSlug, environmentName } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
@@ -31,10 +31,13 @@ export default {
});
const prepareDatabaseList = () => {
- store.dispatch(
- "database/fetchDatabaseListByPrincipalId",
- currentUser.value.id
- );
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store.dispatch(
+ "database/fetchDatabaseListByPrincipalId",
+ currentUser.value.id
+ );
+ }
};
watchEffect(prepareDatabaseList);
diff --git a/frontend/src/components/ProjectListSidePanel.vue b/frontend/src/components/ProjectListSidePanel.vue
index 4ba111e9e9..681acaa48a 100644
--- a/frontend/src/components/ProjectListSidePanel.vue
+++ b/frontend/src/components/ProjectListSidePanel.vue
@@ -11,7 +11,7 @@
import { computed, reactive, watchEffect } from "vue";
import { useStore } from "vuex";
-import { Project } from "../types";
+import { Project, UNKNOWN_ID } from "../types";
import { projectName, projectSlug } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
@@ -24,9 +24,12 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
const prepareProjectList = () => {
- store.dispatch("project/fetchProjectListByUser", {
- userId: currentUser.value.id,
- });
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store.dispatch("project/fetchProjectListByUser", {
+ userId: currentUser.value.id,
+ });
+ }
};
watchEffect(prepareProjectList);
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
index 647d394645..0eef116382 100644
--- a/frontend/src/store/modules/auth.ts
+++ b/frontend/src/store/modules/auth.ts
@@ -49,6 +49,14 @@ const actions = {
return convertedUser;
},
+ async logout({ commit }: any) {
+ await axios.post("/api/auth/logout");
+
+ removeCookie("user");
+ commit("setCurrentUser", unknown("PRINCIPAL") as Principal);
+ return unknown("PRINCIPAL") as Principal;
+ },
+
async signup({ commit, dispatch, rootGetters }: any, signupInfo: SignupInfo) {
const newUser = (
await axios.post("/api/auth/signup", {
@@ -114,12 +122,6 @@ const actions = {
}
}
},
-
- async logout({ commit }: any) {
- removeCookie("user");
- commit("setCurrentUser", unknown("PRINCIPAL") as Principal);
- return unknown("PRINCIPAL") as Principal;
- },
};
const mutations = {
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index aeb5b0d8a1..3d6c0bfa59 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -44,7 +44,13 @@ import { useStore } from "vuex";
import EnvironmentTable from "../components/EnvironmentTable.vue";
import InstanceTable from "../components/InstanceTable.vue";
import ProjectTable from "../components/ProjectTable.vue";
-import { Environment, Instance, Principal, Project } from "../types";
+import {
+ Environment,
+ Instance,
+ Principal,
+ Project,
+ UNKNOWN_ID,
+} from "../types";
import { isDBAOrOwner } from "../utils";
const PROJECT_TAB = 0;
@@ -72,10 +78,13 @@ export default {
const store = useStore();
const prepareList = () => {
- store.dispatch("project/fetchProjectListByUser", {
- userId: currentUser.value.id,
- rowStatusList: ["ARCHIVED"],
- });
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store.dispatch("project/fetchProjectListByUser", {
+ userId: currentUser.value.id,
+ rowStatusList: ["ARCHIVED"],
+ });
+ }
if (isDBAOrOwner(currentUser.value.role)) {
store.dispatch("instance/fetchInstanceList", ["ARCHIVED"]);
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 802a7cfb26..c20343fcaf 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -37,7 +37,7 @@ import { useStore } from "vuex";
import { useRouter } from "vue-router";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import DatabaseTable from "../components/DatabaseTable.vue";
-import { Environment, Database } from "../types";
+import { Environment, Database, UNKNOWN_ID } from "../types";
import { sortDatabaseList } from "../utils";
interface LocalState {
@@ -92,14 +92,17 @@ export default {
});
const prepareDatabaseList = () => {
- store
- .dispatch(
- "database/fetchDatabaseListByPrincipalId",
- currentUser.value.id
- )
- .then((list) => {
- state.databaseList = sortDatabaseList(list, environmentList.value);
- });
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store
+ .dispatch(
+ "database/fetchDatabaseListByPrincipalId",
+ currentUser.value.id
+ )
+ .then((list) => {
+ state.databaseList = sortDatabaseList(list, environmentList.value);
+ });
+ }
};
watchEffect(prepareDatabaseList);
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index f9a6b7a6f0..0f0510d62e 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -47,7 +47,7 @@ import { useRouter } from "vue-router";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import IssueTable from "../components/IssueTable.vue";
import { activeEnvironment, activeTask } from "../utils";
-import { Environment, Issue, TaskStatus } from "../types";
+import { Environment, Issue, TaskStatus, UNKNOWN_ID } from "../types";
interface LocalState {
createdList: Issue[];
@@ -92,42 +92,45 @@ export default {
});
const prepareIssueList = () => {
- store
- .dispatch("issue/fetchIssueListForUser", currentUser.value.id)
- .then((issueList: Issue[]) => {
- state.assignedList = [];
- state.createdList = [];
- state.subscribeList = [];
- state.closeList = [];
- for (const issue of issueList) {
- // "OPEN"
- if (issue.status === "OPEN") {
- if (issue.assignee?.id === currentUser.value.id) {
- state.assignedList.push(issue);
- } else if (issue.creator.id === currentUser.value.id) {
- state.createdList.push(issue);
- } else if (
- issue.subscriberList.find(
- (item) => item.id == currentUser.value.id
- )
- ) {
- state.subscribeList.push(issue);
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store
+ .dispatch("issue/fetchIssueListForUser", currentUser.value.id)
+ .then((issueList: Issue[]) => {
+ state.assignedList = [];
+ state.createdList = [];
+ state.subscribeList = [];
+ state.closeList = [];
+ for (const issue of issueList) {
+ // "OPEN"
+ if (issue.status === "OPEN") {
+ if (issue.assignee?.id === currentUser.value.id) {
+ state.assignedList.push(issue);
+ } else if (issue.creator.id === currentUser.value.id) {
+ state.createdList.push(issue);
+ } else if (
+ issue.subscriberList.find(
+ (item) => item.id == currentUser.value.id
+ )
+ ) {
+ state.subscribeList.push(issue);
+ }
}
- }
- // "DONE" or "CANCELED"
- else if (issue.status === "DONE" || issue.status === "CANCELED") {
- if (
- issue.creator.id === currentUser.value.id ||
- issue.assignee?.id === currentUser.value.id ||
- issue.subscriberList.find(
- (item) => item.id == currentUser.value.id
- )
- ) {
- state.closeList.push(issue);
+ // "DONE" or "CANCELED"
+ else if (issue.status === "DONE" || issue.status === "CANCELED") {
+ if (
+ issue.creator.id === currentUser.value.id ||
+ issue.assignee?.id === currentUser.value.id ||
+ issue.subscriberList.find(
+ (item) => item.id == currentUser.value.id
+ )
+ ) {
+ state.closeList.push(issue);
+ }
}
}
- }
- });
+ });
+ }
};
watchEffect(prepareIssueList);
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index 8eac36a18a..79ee59bdf3 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -207,11 +207,14 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
const prepareMessageList = () => {
- store
- .dispatch("message/fetchMessageListByUser", currentUser.value.id)
- .then((list: Message[]) => {
- state.messageList = list;
- });
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store
+ .dispatch("message/fetchMessageListByUser", currentUser.value.id)
+ .then((list: Message[]) => {
+ state.messageList = list;
+ });
+ }
};
watchEffect(prepareMessageList);
diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vue
index 2e45df7d15..0e2e23356b 100644
--- a/frontend/src/views/ProjectDashboard.vue
+++ b/frontend/src/views/ProjectDashboard.vue
@@ -31,7 +31,7 @@
import { watchEffect, computed, onMounted, reactive, ref } from "vue";
import { useStore } from "vuex";
import ProjectTable from "../components/ProjectTable.vue";
-import { Project } from "../types";
+import { Project, UNKNOWN_ID } from "../types";
interface LocalState {
projectList: Project[];
@@ -74,13 +74,16 @@ export default {
});
const prepareProjectList = () => {
- store
- .dispatch("project/fetchProjectListByUser", {
- userId: currentUser.value.id,
- })
- .then((projectList: Project[]) => {
- state.projectList = projectList;
- });
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store
+ .dispatch("project/fetchProjectListByUser", {
+ userId: currentUser.value.id,
+ })
+ .then((projectList: Project[]) => {
+ state.projectList = projectList;
+ });
+ }
};
watchEffect(prepareProjectList);
diff --git a/server/auth.go b/server/auth.go
index 2cff257340..7f1d6118fe 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -62,6 +62,15 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return nil
})
+ g.POST("/auth/logout", func(c echo.Context) error {
+ removeTokenCookie(c, accessTokenCookieName)
+ removeTokenCookie(c, refreshTokenCookieName)
+
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
+ c.Response().WriteHeader(http.StatusOK)
+ return nil
+ })
+
g.POST("/auth/signup", func(c echo.Context) error {
signup := &api.Signup{}
if err := jsonapi.UnmarshalPayload(c.Request().Body, signup); err != nil {
diff --git a/server/jwt.go b/server/jwt.go
index e633b70b8f..9b4d5f2c70 100644
--- a/server/jwt.go
+++ b/server/jwt.go
@@ -129,6 +129,16 @@ func setTokenCookie(c echo.Context, name, token string, expiration time.Time) {
c.SetCookie(cookie)
}
+func removeTokenCookie(c echo.Context, name string) {
+ cookie := new(http.Cookie)
+ cookie.Name = name
+ cookie.Value = ""
+ cookie.Expires = time.Unix(0, 0)
+ cookie.Path = "/"
+
+ c.SetCookie(cookie)
+}
+
// Purpose of this cookie is to store the user's id.
func setUserCookie(c echo.Context, user *api.Principal, expiration time.Time) {
cookie := new(http.Cookie)