Skip to content

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

fix: only use last login time to check setup

ecmadaoa296bc6666bb
diff --git a/frontend/src/stores/app/auth.ts b/frontend/src/stores/app/auth.ts
index 9248ed91e8..38b92525eb 100644
--- a/frontend/src/stores/app/auth.ts
+++ b/frontend/src/stores/app/auth.ts
@@ -41,20 +41,8 @@ function readResetPassword(email: string): boolean {
}
}
-/**
- * Returns true if the user should be prompted to set up their profile.
- * First-time login with an auto-generated name (email local-part or full
- * email). Ported verbatim from the legacy Pinia auth store.
- */
-function needsProfileSetup(user: User): boolean {
- if (user.profile?.lastLoginTime) return false;
- const name = user.title;
- const email = user.email;
- if (!name || !email) return false;
- if (name === email) return true;
- const atIndex = email.indexOf("@");
- if (atIndex > 0 && name === email.substring(0, atIndex)) return true;
- return false;
+function isFirstLogin(user: User): boolean {
+ return !user.profile?.lastLoginTime;
}
export const createAuthSlice: AppSliceCreator<AuthSlice> = (set, get) => ({
@@ -210,7 +198,7 @@ export const createAuthSlice: AppSliceCreator<AuthSlice> = (set, get) => ({
});
return;
}
- if (resp.user && needsProfileSetup(resp.user)) {
+ if (resp.user && isFirstLogin(resp.user)) {
set({ workspacePolicy: undefined });
await get()
.fetchWorkspaceIamPolicy(true)
diff --git a/frontend/src/stores/app/index.test.ts b/frontend/src/stores/app/index.test.ts
index c815f37239..e120f30274 100644
--- a/frontend/src/stores/app/index.test.ts
+++ b/frontend/src/stores/app/index.test.ts
@@ -645,10 +645,10 @@ describe("useAppStore", () => {
expect(mocks.navigateToPath).toHaveBeenCalledWith("/", { replace: true });
});
- test("self-host first login uses the unified workspace setup route", async () => {
+ test("self-host first login with an IdP display name uses the unified workspace setup route", async () => {
const firstLoginUser = createProto(UserSchema, {
...user,
- title: user.email,
+ title: "Alice Doe",
});
mocks.login.mockResolvedValue({
requireResetPassword: false,
@@ -661,6 +661,56 @@ describe("useAppStore", () => {
saas: false,
});
mocks.getWorkspace.mockResolvedValue({ name: user.workspace });
+ mocks.getSetting.mockResolvedValue(
+ createProto(SettingSchema, {
+ value: createProto(SettingValueSchema, {
+ value: {
+ case: "workspaceProfile",
+ value: createProto(WorkspaceProfileSettingSchema, {}),
+ },
+ }),
+ })
+ );
+ mocks.getIamPolicy.mockResolvedValue(
+ workspacePolicyForUser("roles/workspaceAdmin")
+ );
+ const store = createAppStore();
+
+ await store.getState().login({
+ request: { email: user.email, password: "secret" } as never,
+ });
+
+ expect(mocks.navigateByName).toHaveBeenCalledWith("auth.setup", {
+ query: { redirect: "/" },
+ });
+ });
+
+ test("Cloud first login with an IdP display name uses the unified workspace setup route", async () => {
+ const firstLoginUser = createProto(UserSchema, {
+ ...user,
+ title: "Alice Doe",
+ });
+ mocks.login.mockResolvedValue({
+ requireResetPassword: false,
+ user: firstLoginUser,
+ });
+ mocks.getCurrentUser.mockResolvedValue(firstLoginUser);
+ mocks.getActuatorInfo.mockResolvedValue({
+ workspace: user.workspace,
+ userCountInIam: 1,
+ saas: true,
+ });
+ mocks.getWorkspace.mockResolvedValue({ name: user.workspace });
+ mocks.getSetting.mockResolvedValue(
+ createProto(SettingSchema, {
+ value: createProto(SettingValueSchema, {
+ value: {
+ case: "workspaceProfile",
+ value: createProto(WorkspaceProfileSettingSchema, {}),
+ },
+ }),
+ })
+ );
mocks.getIamPolicy.mockResolvedValue(
workspacePolicyForUser("roles/workspaceAdmin")
);