Skip to content

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

chore: donot redirect from signin modal (#18186)

ecmadao3ffbd3225c32
diff --git a/frontend/src/components/PasswordSigninForm.vue b/frontend/src/components/PasswordSigninForm.vue
index c0ca2166dd..311b628dfc 100644
--- a/frontend/src/components/PasswordSigninForm.vue
+++ b/frontend/src/components/PasswordSigninForm.vue
@@ -32,7 +32,7 @@
<RequiredStar />
</div>
<router-link
- v-if="props.showForgotPassword"
+ v-if="showForgotPassword"
:to="{
path: '/auth/password-forgot',
query: {
@@ -73,7 +73,7 @@
attr-type="submit"
type="primary"
:disabled="!allowSignin"
- :loading="state.isLoading"
+ :loading="loading"
size="large"
style="width: 100%"
>
@@ -92,34 +92,39 @@ import { computed, onMounted, reactive } from "vue";
import { useRoute } from "vue-router";
import { BBTextField } from "@/bbkit";
import RequiredStar from "@/components/RequiredStar.vue";
-import { useActuatorV1Store, useAuthStore } from "@/store";
-import { LoginRequestSchema } from "@/types/proto-es/v1/auth_service_pb";
+import { useActuatorV1Store } from "@/store";
+import {
+ type LoginRequest,
+ LoginRequestSchema,
+} from "@/types/proto-es/v1/auth_service_pb";
interface LocalState {
email: string;
password: string;
showPassword: boolean;
- isLoading: boolean;
}
-const props = withDefaults(
+withDefaults(
defineProps<{
showForgotPassword?: boolean;
+ loading: boolean;
}>(),
{
showForgotPassword: true,
}
);
+const emit = defineEmits<{
+ (event: "signin", payload: LoginRequest): void;
+}>();
+
const route = useRoute();
-const authStore = useAuthStore();
const { isDemo } = storeToRefs(useActuatorV1Store());
const state = reactive<LocalState>({
email: "",
password: "",
showPassword: false,
- isLoading: false,
});
onMounted(async () => {
@@ -146,18 +151,12 @@ const allowSignin = computed(() => {
});
const trySignin = async () => {
- if (state.isLoading) return;
- state.isLoading = true;
- try {
- await authStore.login(
- create(LoginRequestSchema, {
- email: state.email,
- password: state.password,
- web: true,
- })
- );
- } finally {
- state.isLoading = false;
- }
+ emit(
+ "signin",
+ create(LoginRequestSchema, {
+ email: state.email,
+ password: state.password,
+ })
+ );
};
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index cf29e26ef8..49194c9deb 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1572,7 +1572,9 @@
"title": "Your session is about to end",
"description": "You've been inactive for a while. For your security, we'll automatically sign you out in {minutes} minutes.",
"stay-signed-in": "Stay signed in"
- }
+ },
+ "back-to-signin": "Back to Sign in",
+ "close-window": "Close this window"
},
"policy": {
"rollout": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 74374028b1..9e378de84a 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1572,7 +1572,9 @@
"title": "Tu sesión está a punto de terminar",
"description": "Has estado inactivo un tiempo. Por tu seguridad, cerraremos tu sesión automáticamente en {minutes} minutos.",
"stay-signed-in": "Permanecer conectado"
- }
+ },
+ "back-to-signin": "Volver a Iniciar sesión",
+ "close-window": "Cerrar esta ventana"
},
"policy": {
"rollout": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 5eb5e3462c..0b5706d762 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1572,7 +1572,9 @@
"title": "セッションの有効期限が近づいています",
"description": "しばらく操作がありませんでした。セキュリティのため、{minutes}分後に自動的にログアウトします。",
"stay-signed-in": "ログインしたままにする"
- }
+ },
+ "back-to-signin": "サインインに戻る",
+ "close-window": "このウィンドウを閉じる"
},
"policy": {
"rollout": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index a96d3f2265..d675331719 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1572,7 +1572,9 @@
"title": "Phiên của bạn sắp kết thúc",
"description": "Bạn đã không hoạt động trong một thời gian. Để bảo mật cho bạn, chúng tôi sẽ tự động đăng xuất bạn sau {minutes} phút nữa.",
"stay-signed-in": "Tiếp tục duy trì đăng nhập"
- }
+ },
+ "back-to-signin": "Quay lại Đăng nhập",
+ "close-window": "Đóng cửa sổ này"
},
"policy": {
"rollout": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index a056a339cf..3f0a515c08 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1572,7 +1572,9 @@
"title": "您的会话即将结束",
"description": "您已有一段时间未活动。为了您的安全,我们将在{minutes}分钟后自动退出您的登录。",
"stay-signed-in": "保持登录状态"
- }
+ },
+ "back-to-signin": "返回登录页面",
+ "close-window": "关闭此窗口"
},
"policy": {
"rollout": {
diff --git a/frontend/src/router/auth.ts b/frontend/src/router/auth.ts
index bb1f4e0d71..838ce14d7b 100644
--- a/frontend/src/router/auth.ts
+++ b/frontend/src/router/auth.ts
@@ -27,6 +27,7 @@ const authRoutes: RouteRecordRaw[] = [
component: () => import("@/views/auth/Signin.vue"),
},
{
+ // We need the admin as the backdoor for the workspace admin.
path: "admin",
name: AUTH_SIGNIN_ADMIN_MODULE,
meta: { title: () => t("common.sign-in-as-admin") },
diff --git a/frontend/src/store/modules/v1/auth.ts b/frontend/src/store/modules/v1/auth.ts
index 6ca6303b88..b4e4d8f6cf 100644
--- a/frontend/src/store/modules/v1/auth.ts
+++ b/frontend/src/store/modules/v1/auth.ts
@@ -77,20 +77,37 @@ export const useAuthStore = defineStore("auth_v1", () => {
return query.get("redirect");
};
- const login = async (request: LoginRequest, redirect: string = "") => {
- const resp = await authServiceClientConnect.login(request, {
- contextValues: createContextValues().set(ignoredCodesContextKey, [
- Code.NotFound,
- ]),
- });
- const redirectUrl = redirect || getRedirectQuery() || "/";
+ // sometimes we have to redirect users even if we don't want to redirect them.
+ // for example, the user is forced to reset their password,
+ // or the user is using the LDAP to signin.
+ const login = async ({
+ request,
+ redirect = true,
+ redirectUrl,
+ }: {
+ request: LoginRequest;
+ redirect?: boolean;
+ redirectUrl?: string;
+ }) => {
+ const resp = await authServiceClientConnect.login(
+ create(LoginRequestSchema, {
+ ...request,
+ web: true,
+ }),
+ {
+ contextValues: createContextValues().set(ignoredCodesContextKey, [
+ Code.NotFound,
+ ]),
+ }
+ );
+ let nextPage = redirectUrl ?? (getRedirectQuery() || "/");
if (resp.mfaTempToken) {
unauthenticatedOccurred.value = false;
return router.push({
name: AUTH_MFA_MODULE,
query: {
mfaTempToken: resp.mfaTempToken,
- redirect: redirectUrl,
+ redirect: nextPage,
},
});
}
@@ -118,7 +135,6 @@ export const useAuthStore = defineStore("auth_v1", () => {
});
}
const mode = useAppFeature("bb.feature.database-change-mode");
- let nextPage = redirectUrl;
if (mode.value === DatabaseChangeMode.EDITOR) {
const route = router.resolve({
name: SQL_EDITOR_HOME_MODULE,
@@ -133,7 +149,9 @@ export const useAuthStore = defineStore("auth_v1", () => {
},
});
}
- return router.replace(nextPage);
+ if (redirect) {
+ router.replace(nextPage);
+ }
};
const signup = async (request: Partial<User>) => {
@@ -147,13 +165,14 @@ export const useAuthStore = defineStore("auth_v1", () => {
user: user,
});
await userServiceClientConnect.createUser(createRequest);
- await login(
- create(LoginRequestSchema, {
+ await login({
+ request: create(LoginRequestSchema, {
email: request.email,
password: request.password,
web: true,
- })
- );
+ }),
+ redirect: true,
+ });
};
const logout = async () => {
diff --git a/frontend/src/utils/auth.ts b/frontend/src/utils/auth.ts
index 4930bb4184..d8a13baa9f 100644
--- a/frontend/src/utils/auth.ts
+++ b/frontend/src/utils/auth.ts
@@ -5,7 +5,6 @@ import {
AUTH_OIDC_CALLBACK_MODULE,
AUTH_PASSWORD_FORGOT_MODULE,
AUTH_PASSWORD_RESET_MODULE,
- AUTH_SIGNIN_ADMIN_MODULE,
AUTH_SIGNIN_MODULE,
AUTH_SIGNUP_MODULE,
} from "@/router/auth";
@@ -13,7 +12,6 @@ import {
export const isAuthRelatedRoute = (routeName: string) => {
return [
AUTH_SIGNIN_MODULE,
- AUTH_SIGNIN_ADMIN_MODULE,
AUTH_SIGNUP_MODULE,
AUTH_MFA_MODULE,
AUTH_PASSWORD_RESET_MODULE,
diff --git a/frontend/src/views/OAuthCallback.vue b/frontend/src/views/OAuthCallback.vue
index cedf996381..267be81b6b 100644
--- a/frontend/src/views/OAuthCallback.vue
+++ b/frontend/src/views/OAuthCallback.vue
@@ -3,10 +3,10 @@
<div v-if="state.hasError" class="mt-2">
<div>{{ state.message }}</div>
<NButton v-if="state.oAuthState?.popup" @click="window.close()">
- Close
+ {{ $t("common.close") }}
</NButton>
<router-link v-else :to="{ name: AUTH_SIGNIN_MODULE }" class="btn-normal">
- Back to Sign in
+ {{ $t("auth.back-to-signin") }}
</router-link>
</div>
<div v-else class="mt-2">
@@ -19,7 +19,7 @@
class="mt-4"
@click="window.close()"
>
- Close this window
+ {{ $t("auth.close-window") }}
</NButton>
</div>
</div>
@@ -183,28 +183,21 @@ const triggerAuthCallback = async () => {
return;
}
- await authStore.login(
- create(LoginRequestSchema, {
+ await authStore.login({
+ request: create(LoginRequestSchema, {
idpName,
idpContext: {
- context: isOidc
- ? {
- case: "oidcContext",
- value: {
- code: state.payload.code,
- },
- }
- : {
- case: "oauth2Context",
- value: {
- code: state.payload.code,
- },
- },
+ context: {
+ case: isOidc ? "oidcContext" : "oauth2Context",
+ value: {
+ code: state.payload.code,
+ },
+ },
},
- web: true,
}),
- oAuthState.redirect
- );
+ redirect: true,
+ redirectUrl: oAuthState.redirect,
+ });
}
};
</script>
diff --git a/frontend/src/views/auth/MultiFactor.vue b/frontend/src/views/auth/MultiFactor.vue
index fecf30ba23..275b2221d9 100644
--- a/frontend/src/views/auth/MultiFactor.vue
+++ b/frontend/src/views/auth/MultiFactor.vue
@@ -111,9 +111,11 @@ const challenge = async () => {
mfaContext.recoveryCode = state.recoveryCode;
}
await authStore.login({
- web: true,
- mfaTempToken: mfaTempToken.value,
- ...mfaContext,
+ request: {
+ mfaTempToken: mfaTempToken.value,
+ ...mfaContext,
+ },
+ redirect: true,
});
};
</script>
diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vue
index 82af40f007..04a378e2ee 100644
--- a/frontend/src/views/auth/Signin.vue
+++ b/frontend/src/views/auth/Signin.vue
@@ -17,7 +17,10 @@
name="standard"
tab="Standard"
>
- <PasswordSigninForm />
+ <PasswordSigninForm
+ :loading="state.isLoading"
+ @signin="trySignin"
+ />
<div class="mt-3">
<div
@@ -59,7 +62,7 @@
>
<form
class="flex flex-col gap-y-6"
- @submit.prevent="trySignin(identityProvider.name)"
+ @submit.prevent="trySigninWithIdp(identityProvider.name)"
>
<div>
<label
@@ -193,7 +196,10 @@ import {
useIdentityProviderStore,
} from "@/store";
import { idpNamePrefix } from "@/store/modules/v1/common";
-import { LoginRequestSchema } from "@/types/proto-es/v1/auth_service_pb";
+import {
+ type LoginRequest,
+ LoginRequestSchema,
+} from "@/types/proto-es/v1/auth_service_pb";
import type { IdentityProvider } from "@/types/proto-es/v1/idp_service_pb";
import { IdentityProviderType } from "@/types/proto-es/v1/idp_service_pb";
import { openWindowForSSO } from "@/utils";
@@ -201,9 +207,12 @@ import AuthFooter from "./AuthFooter.vue";
const props = withDefaults(
defineProps<{
+ redirect?: boolean;
+ redirectUrl?: string;
allowSignup?: boolean;
}>(),
{
+ redirect: true,
allowSignup: true,
}
);
@@ -303,18 +312,25 @@ const allowIdPSignin = computed(() => {
});
// Mainly for LDAP signin.
-const trySignin = async (idpName: string) => {
+const trySigninWithIdp = (idpName: string) => {
+ trySignin(
+ create(LoginRequestSchema, {
+ email: state.email,
+ password: state.password,
+ idpName: idpName,
+ })
+ );
+};
+
+const trySignin = async (request: LoginRequest) => {
if (state.isLoading) return;
state.isLoading = true;
try {
- await authStore.login(
- create(LoginRequestSchema, {
- email: state.email,
- password: state.password,
- web: true,
- idpName: idpName,
- })
- );
+ await authStore.login({
+ request,
+ redirect: props.redirect,
+ redirectUrl: props.redirectUrl,
+ });
} finally {
state.isLoading = false;
}
diff --git a/frontend/src/views/auth/SigninAdmin.vue b/frontend/src/views/auth/SigninAdmin.vue
index 4a0de4242c..72fdaeb3ef 100644
--- a/frontend/src/views/auth/SigninAdmin.vue
+++ b/frontend/src/views/auth/SigninAdmin.vue
@@ -7,7 +7,11 @@
<p class="text-xl pl-1 font-medium mb-4">
{{ $t("common.sign-in-as-admin") }}
</p>
- <PasswordSigninForm :show-forgot-password="false" />
+ <PasswordSigninForm
+ :show-forgot-password="false"
+ :loading="isLoading"
+ @signin="trySignin"
+ />
</NCard>
</div>
</div>
@@ -16,7 +20,26 @@
<script lang="ts" setup>
import { NCard } from "naive-ui";
+import { ref } from "vue";
import BytebaseLogo from "@/components/BytebaseLogo.vue";
import PasswordSigninForm from "@/components/PasswordSigninForm.vue";
+import { useAuthStore } from "@/store";
+import { type LoginRequest } from "@/types/proto-es/v1/auth_service_pb";
import AuthFooter from "./AuthFooter.vue";
-</script>
+
+const isLoading = ref(false);
+const authStore = useAuthStore();
+
+const trySignin = async (request: LoginRequest) => {
+ if (isLoading.value) return;
+ isLoading.value = true;
+ try {
+ await authStore.login({
+ request,
+ redirect: true,
+ });
+ } finally {
+ isLoading.value = false;
+ }
+};
+</script>
\ No newline at end of file
diff --git a/frontend/src/views/auth/SigninModal.vue b/frontend/src/views/auth/SigninModal.vue
index de0c4a57bb..9f5040a524 100644
--- a/frontend/src/views/auth/SigninModal.vue
+++ b/frontend/src/views/auth/SigninModal.vue
@@ -8,7 +8,11 @@
>
<div class="flex items-center w-auto md:min-w-96 max-w-full h-auto md:py-4">
<div class="flex flex-col justify-center items-center flex-1 gap-y-2">
- <Signin :allow-signup="false">
+ <Signin
+ :redirect="false"
+ :redirect-url="currentPath"
+ :allow-signup="false"
+ >
<template #footer>
<NButton quaternary size="small" @click="logout">
{{ $t("common.logout") }}
@@ -22,13 +26,18 @@
<script lang="tsx" setup>
import { NButton } from "naive-ui";
+import { computed } from "vue";
+import { useRoute } from "vue-router";
import { BBModal } from "@/bbkit";
import { useAuthStore } from "@/store";
import Signin from "@/views/auth/Signin.vue";
const authStore = useAuthStore();
+const route = useRoute();
const logout = () => {
authStore.logout();
};
+
+const currentPath = computed(() => route.fullPath);
</script>