Skip to content

Commit 69f1474

Browse files
committed
feat: Allow forcing basic auth in development
https://harperdb.atlassian.net/browse/STUDIO-588
1 parent 06f0bcb commit 69f1474

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const forceBasicAuth = import.meta.env.VITE_FORCE_BASIC_AUTH === 'true';
12
export const isLocalStudio = import.meta.env.VITE_LOCAL_STUDIO === 'true';
23
export const localStudioDevUrl = import.meta.env.VITE_LOCAL_STUDIO_DEV_URL;
34
export const defaultOperationsApiPort = 9925;

src/features/instance/operations/mutations/useInstanceLoginMutation.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { forceBasicAuth } from '@/config/constants';
12
import { InstanceClientIdConfig } from '@/config/instanceClientConfig';
23
import { authStore } from '@/features/auth/store/authStore';
34
import { getInstanceUserInfo } from '@/features/instance/operations/queries/getInstanceUserInfo';
@@ -26,29 +27,31 @@ export async function onInstanceLoginSubmit({
2627
password,
2728
});
2829

29-
// Attempt to use the login with session storage only.
30-
try {
31-
const user = await getInstanceUserInfo({ instanceClient });
32-
return {
33-
message,
34-
user,
35-
};
36-
} catch (err) {
37-
console.error('Failed to get user after login, trying basic auth', err);
38-
39-
const user = await getInstanceUserInfo({
40-
instanceClient,
41-
auth: {
42-
username,
43-
password,
44-
},
45-
});
46-
authStore.flagForBasicAuth(entityId, { username, password });
47-
return {
48-
message,
49-
user,
50-
};
30+
if (!forceBasicAuth) {
31+
// Attempt to use the login with session storage only.
32+
try {
33+
const user = await getInstanceUserInfo({ instanceClient });
34+
return {
35+
message,
36+
user,
37+
};
38+
} catch (err) {
39+
console.error('Failed to get user after login, trying basic auth', err);
40+
}
5141
}
42+
43+
const user = await getInstanceUserInfo({
44+
instanceClient,
45+
auth: {
46+
username,
47+
password,
48+
},
49+
});
50+
authStore.flagForBasicAuth(entityId, { username, password });
51+
return {
52+
message,
53+
user,
54+
};
5255
}
5356

5457
export function useInstanceLoginMutation() {

src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface ImportMetaEnv {
44
readonly DEV: string;
55
readonly VITE_STUDIO_VERSION: string;
66
readonly VITE_LOCAL_STUDIO: string; //INFO: This flag is the local version of studio ran on HarperDb instances
7+
readonly VITE_FORCE_BASIC_AUTH: string;
78
readonly VITE_ENV_NAME: string;
89
readonly VITE_PUBLIC_STRIPE_KEY: string;
910
readonly VITE_LOCAL_STUDIO_DEV_URL: string;

0 commit comments

Comments
 (0)