Skip to content

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

feat: migrate auth/logout to v1 API (#4085)

Danny Xue8cbb01df012
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
index 6466d6a48f..a6a96e9fe2 100644
--- a/frontend/src/store/modules/auth.ts
+++ b/frontend/src/store/modules/auth.ts
@@ -67,7 +67,7 @@ export const useAuthStore = defineStore("auth", {
async logout() {
const unknownPrincipal = unknown("PRINCIPAL") as Principal;
try {
- await axios.post("/api/auth/logout");
+ await axios.post("/v1/auth/logout");
} finally {
this.setCurrentUser(unknownPrincipal);
}
diff --git a/server/auth.go b/server/auth.go
index fb9f037eb1..79a1e0da79 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -15,7 +15,6 @@ import (
metricAPI "github.com/bytebase/bytebase/metric"
"github.com/bytebase/bytebase/plugin/metric"
"github.com/bytebase/bytebase/plugin/vcs"
- "github.com/bytebase/bytebase/server/api/auth"
"github.com/bytebase/bytebase/server/component/activity"
)
@@ -187,16 +186,6 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return nil
})
- g.POST("/auth/logout", func(c echo.Context) error {
- removeTokenCookie(c, auth.AccessTokenCookieName)
- removeTokenCookie(c, auth.RefreshTokenCookieName)
- removeUserCookie(c)
-
- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
- c.Response().WriteHeader(http.StatusOK)
- return nil
- })
-
g.POST("/auth/signup", func(c echo.Context) error {
ctx := c.Request().Context()
signUp := &api.SignUp{}
diff --git a/server/jwt.go b/server/jwt.go
index ff74a7a305..961c8fac0c 100644
--- a/server/jwt.go
+++ b/server/jwt.go
@@ -72,15 +72,6 @@ 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)
@@ -94,15 +85,6 @@ func setUserCookie(c echo.Context, user *api.Principal, expiration time.Time) {
c.SetCookie(cookie)
}
-func removeUserCookie(c echo.Context) {
- cookie := new(http.Cookie)
- cookie.Name = "user"
- cookie.Value = ""
- cookie.Expires = time.Unix(0, 0)
- cookie.Path = "/"
- c.SetCookie(cookie)
-}
-
func findAccessToken(c echo.Context) (string, error) {
if common.HasPrefixes(c.Path(), openAPIPrefix) {
authHeader := c.Request().Header.Get("Authorization")