Skip to content

Commit f8afade

Browse files
committedMar 28, 2024
add hasNoAuth method
1 parent 123b6cb commit f8afade

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed
 

‎packages/web-console/src/modules/OAuth2/utils.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ConsoleSettingsShape, ConsoleSettings } from "../../store/Console/types"
1+
import {
2+
ConsoleSettingsShape,
3+
ConsoleSettings,
4+
} from "../../store/Console/types"
25

36
type TokenPayload = Partial<{
47
grant_type: string
@@ -10,7 +13,9 @@ type TokenPayload = Partial<{
1013
}>
1114

1215
const getBaseURL = (config: ConsoleSettings) => {
13-
return `${config["acl.oidc.tls.enabled"] ? "https" : "http"}://${config["acl.oidc.host"]}:${config["acl.oidc.port"]}`
16+
return `${config["acl.oidc.tls.enabled"] ? "https" : "http"}://${
17+
config["acl.oidc.host"]
18+
}:${config["acl.oidc.port"]}`
1419
}
1520

1621
export const getAuthorisationURL = ({
@@ -67,3 +72,8 @@ export const getAuthToken = async (
6772
},
6873
)
6974
}
75+
76+
export const hasNoAuth = (config: ConsoleSettings) =>
77+
(config["acl.basic.auth.realm.enabled"] !== undefined &&
78+
!config["acl.basic.auth.realm.enabled"]) ||
79+
(config["acl.oidc.enabled"] == undefined && !config["acl.oidc.enabled"])

‎packages/web-console/src/providers/AuthProvider.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getAuthorisationURL,
1010
getAuthToken,
1111
getTokenExpirationDate,
12+
hasNoAuth,
1213
} from "../modules/OAuth2/utils"
1314
import {
1415
generateCodeChallenge,
@@ -52,9 +53,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
5253
const [loading, setLoading] = useState(true)
5354
const [sessionData, setSessionData] =
5455
useState<ContextProps["sessionData"]>(undefined)
55-
const [ready, setReady] = useState(
56-
!settings["acl.basic.auth.realm.enabled"] && !settings["acl.oidc.enabled"],
57-
)
56+
const [ready, setReady] = useState(hasNoAuth(settings))
5857
const [errorMessage, setErrorMessage] = useState<string | undefined>(
5958
undefined,
6059
)

‎packages/web-console/src/providers/QuestProvider/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { getValue } from "../../utils/localStorage"
3737
import { StoreKey } from "../../utils/localStorage/types"
3838
import { formatCommitHash, formatVersion } from "./services"
3939
import { Versions } from "./types"
40+
import { hasNoAuth } from "../../modules/OAuth2/utils"
4041

4142
const questClient = new QuestDB.Client()
4243

@@ -63,9 +64,7 @@ export const QuestProvider = ({ children }: PropsWithChildren<Props>) => {
6364
const settings = useSelector(selectors.console.getSettings)
6465
const { sessionData, refreshAuthToken } = useAuth()
6566
const [authCheckFinished, setAuthCheckFinished] = useState(
66-
settings["acl.basic.auth.realm.enabled"] ||
67-
(!settings["acl.oidc.enabled"] &&
68-
!settings["acl.basic.auth.realm.enabled"]),
67+
hasNoAuth(settings),
6968
)
7069
const [buildVersion, setBuildVersion] = useState<Versions>(
7170
defaultValues.buildVersion,

0 commit comments

Comments
 (0)
Failed to load comments.