Skip to content

Commit

Permalink
chore(ui): fix token refresh (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
glasstiger authored Nov 25, 2024
1 parent 0494e85 commit 9be3289
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/browser-tests/questdb
Submodule questdb updated 300 files
4 changes: 1 addition & 3 deletions packages/web-console/src/providers/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
const [state, dispatch] = useReducer(reducer, initialState)

const setAuthToken = (tokenResponse: AuthPayload, settings: Settings) => {
if (tokenResponse.access_token && tokenResponse.id_token) {
if (tokenResponse.access_token) {
tokenResponse.groups_encoded_in_token = settings["acl.oidc.groups.encoded.in.token"]
tokenResponse.expires_at = getTokenExpirationDate(tokenResponse.expires_in).toString() // convert from the sec offset
setValue(
Expand Down Expand Up @@ -110,11 +110,9 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
}

const refreshAuthToken = async (settings: Settings) => {
const code_verifier = getValue(StoreKey.PKCE_CODE_VERIFIER)
const response = await getAuthToken(settings, {
grant_type: "refresh_token",
refresh_token: getValue(StoreKey.AUTH_REFRESH_TOKEN),
code_verifier,
client_id: settings["acl.oidc.client.id"],
})
const tokenResponse = await response.json()
Expand Down
2 changes: 1 addition & 1 deletion packages/web-console/src/store/Telemetry/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const getConfig: Epic<StoreAction, TelemetryAction, StoreShape> = (
? getValue(StoreKey.AUTH_PAYLOAD)
: "{}"
const token = JSON.parse(authPayload) as AuthPayload
if (token.access_token && token.id_token) {
if (token.access_token) {
quest.setCommonHeaders({
Authorization: `Bearer ${token.groups_encoded_in_token ? token.id_token : token.access_token}`,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/web-console/src/utils/questdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class Client {
if (Client.numOfPendingQueries === 0) {
clearInterval(interval)
const newToken = await this.refreshTokenMethod()
if (newToken.access_token && newToken.id_token) {
if (newToken.access_token) {
this.setCommonHeaders({
...this.commonHeaders,
Authorization: `Bearer ${newToken.groups_encoded_in_token ? newToken.id_token : newToken.access_token}`,
Expand Down

0 comments on commit 9be3289

Please sign in to comment.