fix auth redirect
add token to requests
This commit is contained in:
parent
8cdcb6620f
commit
093cdb97e7
@ -16,13 +16,6 @@ export const keycloakConfig: AuthProviderProps = {
|
||||
authority: oidpSettings.server,
|
||||
client_id: oidpSettings.clientId,
|
||||
redirect_uri: hostURL.toString(),
|
||||
onSigninCallback: () => {
|
||||
window.history.replaceState(
|
||||
{},
|
||||
document.title,
|
||||
window.location.pathname
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const rootStore = new RootStore()
|
||||
@ -42,5 +35,3 @@ root.render(
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
|
||||
|
||||
|
||||
@ -10,12 +10,31 @@ import { FrigateConfig } from "../../types/frigateConfig";
|
||||
import { url } from "inspector";
|
||||
import { RecordSummary } from "../../types/record";
|
||||
import { EventFrigate } from "../../types/event";
|
||||
import { keycloakConfig } from "../..";
|
||||
|
||||
|
||||
const getToken = (): string | undefined => {
|
||||
const key = `oidc.user:${keycloakConfig.authority}:${keycloakConfig.client_id}`;
|
||||
const stored = sessionStorage.getItem(key);
|
||||
const storedObject = stored ? JSON.parse(stored) : null;
|
||||
return storedObject?.access_token;
|
||||
}
|
||||
|
||||
const instanceApi = axios.create({
|
||||
baseURL: proxyURL.toString(),
|
||||
timeout: 30000,
|
||||
});
|
||||
})
|
||||
|
||||
instanceApi.interceptors.request.use(
|
||||
config => {
|
||||
const token = getToken();
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
);
|
||||
|
||||
export const frigateApi = {
|
||||
getConfig: () => instanceApi.get<GetConfig[]>('apiv1/config').then(res => res.data),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user