Skip to content

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

chore: only show login modal when met unauthenticated error (#16663)

ecmadaof39c37e2a8ef
diff --git a/frontend/src/AuthContext.vue b/frontend/src/AuthContext.vue
index 235ee8c62b..927908e659 100644
--- a/frontend/src/AuthContext.vue
+++ b/frontend/src/AuthContext.vue
@@ -38,16 +38,7 @@ onMounted(() => {
return;
}
- const user = await authStore.fetchCurrentUser();
- if (!user) {
- authStore.unauthenticatedOccurred = true;
- pushNotification({
- module: "bytebase",
- style: "WARN",
- title: t("auth.token-expired-title"),
- description: t("auth.token-expired-description"),
- });
- }
+ await authStore.fetchCurrentUser();
}, CHECK_AUTHORIZATION_INTERVAL);
});
diff --git a/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts b/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts
index 6b7c05c5a1..ec72dc5776 100644
--- a/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts
+++ b/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts
@@ -1,10 +1,9 @@
import { Code, ConnectError, type Interceptor } from "@connectrpc/connect";
import { ClientError, ServerError, Status } from "nice-grpc-common";
import type { ClientMiddleware } from "nice-grpc-web";
+import { t } from "@/plugins/i18n";
import { router } from "@/router";
-import { useAuthStore } from "@/store";
-import { UserService } from "@/types/proto-es/v1/user_service_pb";
-import { UserServiceDefinition } from "@/types/proto/v1/user_service";
+import { useAuthStore, pushNotification } from "@/store";
import { silentContextKey, ignoredCodesContextKey } from "../context-key";
export type IgnoreErrorsOptions = {
@@ -40,16 +39,15 @@ export const authInterceptorMiddleware: ClientMiddleware<IgnoreErrorsOptions> =
// omit specified errors
} else {
if (code === Status.UNAUTHENTICATED) {
- // Skip show login modal when the request is to get current user.
- if (
- call.method.path ===
- `/${UserServiceDefinition.fullName}/${UserServiceDefinition.methods.getCurrentUser.name}`
- ) {
- return;
- }
// When receiving 401 and is returned by our server, it means the current
// login user's token becomes invalid. Thus we force the user to login again.
useAuthStore().unauthenticatedOccurred = true;
+ pushNotification({
+ module: "bytebase",
+ style: "WARN",
+ title: t("auth.token-expired-title"),
+ description: t("auth.token-expired-description"),
+ });
} else if (code === Status.PERMISSION_DENIED) {
// Jump to 403 page
router.push({ name: "error.403" });
@@ -95,16 +93,15 @@ export const authInterceptor: Interceptor = (next) => async (req) => {
} else {
if (code === Code.Unauthenticated) {
// Skip show login modal when the request is to get current user.
- if (
- req.method.parent.name === UserService.name &&
- req.method.name === UserService.method.getCurrentUser.name
- ) {
- // skip
- } else {
- // When receiving 401 and is returned by our server, it means the current
- // login user's token becomes invalid. Thus we force the user to login again.
- useAuthStore().unauthenticatedOccurred = true;
- }
+ // When receiving 401 and is returned by our server, it means the current
+ // login user's token becomes invalid. Thus we force the user to login again.
+ useAuthStore().unauthenticatedOccurred = true;
+ pushNotification({
+ module: "bytebase",
+ style: "WARN",
+ title: t("auth.token-expired-title"),
+ description: t("auth.token-expired-description"),
+ });
} else if (code === Code.PermissionDenied) {
// Jump to 403 page
router.push({ name: "error.403" });