resotore lint sidebar fixes

add remove auth params
This commit is contained in:
NlightN22 2024-03-06 02:28:53 +07:00
parent 58e59c2708
commit 5629db199c
5 changed files with 39 additions and 14 deletions

View File

@ -10,6 +10,7 @@ import { Notifications } from '@mantine/notifications';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import RetryErrorPage from './pages/RetryErrorPage'; import RetryErrorPage from './pages/RetryErrorPage';
import { keycloakConfig } from '.'; import { keycloakConfig } from '.';
import { useLocation, useNavigate } from 'react-router-dom';
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {
@ -31,6 +32,8 @@ function App() {
} }
const auth = useAuth() const auth = useAuth()
const location = useLocation()
const navigate = useNavigate()
// automatically sign-in // automatically sign-in
useEffect(() => { useEffect(() => {
@ -54,6 +57,14 @@ function App() {
return <RetryErrorPage backVisible={false} mainVisible={false} onRetry={() => auth.signinRedirect()} /> return <RetryErrorPage backVisible={false} mainVisible={false} onRetry={() => auth.signinRedirect()} />
} }
if (hasAuthParams()) {
const urlParams = new URLSearchParams(location.search);
urlParams.delete('state');
urlParams.delete('session_state');
urlParams.delete('code');
navigate(`${location.pathname}${urlParams.toString() ? '?' + urlParams.toString() : ''}`, { replace: true })
}
if (!auth.isAuthenticated && !auth.isLoading && authErrorCounter < maxErrorAuthCounts) { if (!auth.isAuthenticated && !auth.isLoading && authErrorCounter < maxErrorAuthCounts) {
if (hasAuthParams()) { if (hasAuthParams()) {

View File

@ -17,6 +17,22 @@ export const keycloakConfig: AuthProviderProps = {
authority: oidpSettings.server, authority: oidpSettings.server,
client_id: oidpSettings.clientId, client_id: oidpSettings.clientId,
redirect_uri: hostURL.toString(), redirect_uri: hostURL.toString(),
onSigninCallback: () => {
const currentUrl = new URL(window.location.href);
const params = currentUrl.searchParams;
console.log('params', params.toString())
params.delete('state');
params.delete('session_state');
params.delete('code');
const newUrl = `${window.location.pathname}${params.toString() ? '?' + params.toString() : ''}`
console.log('newUrl', newUrl)
window.history.replaceState({}, document.title, newUrl)
}
} }
const rootStore = new RootStore() const rootStore = new RootStore()
@ -32,9 +48,7 @@ root.render(
<Context.Provider value={rootStore}> <Context.Provider value={rootStore}>
<AuthProvider {...keycloakConfig}> <AuthProvider {...keycloakConfig}>
<BrowserRouter> <BrowserRouter>
{/* <React.StrictMode> */}
<App /> <App />
{/* </React.StrictMode> */}
</BrowserRouter> </BrowserRouter>
</AuthProvider> </AuthProvider>
</Context.Provider> </Context.Provider>

View File

@ -1,9 +1,10 @@
import { Navigate, Route, Routes } from "react-router-dom"; import { Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
import { routes } from "./routes"; import { routes } from "./routes";
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { routesPath } from "./routes.path"; import { routesPath } from "./routes.path";
const AppRouter = () => { const AppRouter = () => {
return ( return (
<Routes> <Routes>
{routes.map(({ path, component }) => {routes.map(({ path, component }) =>

View File

@ -1,12 +1,12 @@
import React, { useContext, useEffect, useRef, useState } from 'react'; import { Aside, Button, Navbar, createStyles } from "@mantine/core";
import { Aside, Button, createStyles, Navbar } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks"; import { useDisclosure } from "@mantine/hooks";
import { observer } from 'mobx-react-lite';
import React, { useContext, useEffect, useRef, useState } from 'react';
import { Context } from '../..';
import { dimensions } from '../dimensions/dimensions';
import { strings } from '../strings/strings';
import { useMantineSize } from '../utils/mantine.size.convertor'; import { useMantineSize } from '../utils/mantine.size.convertor';
import { SideButton } from './SideButton'; import { SideButton } from './SideButton';
import { strings } from '../strings/strings';
import { dimensions } from '../dimensions/dimensions';
import { Context } from '../..';
import { observer } from 'mobx-react-lite';
export interface SideBarProps { export interface SideBarProps {
isHidden: (isHidden: boolean) => void, isHidden: (isHidden: boolean) => void,
@ -48,7 +48,7 @@ const SideBar = ({ isHidden, side, children }: SideBarProps) => {
} else if (!sideBarsStore.rightVisible && side === 'right' && visible) { } else if (!sideBarsStore.rightVisible && side === 'right' && visible) {
close() close()
} }
}, [sideBarsStore.rightVisible, close, open, side, visible]) }, [sideBarsStore.rightVisible])
const [leftChildren, setLeftChildren] = useState<React.ReactNode>(() => { const [leftChildren, setLeftChildren] = useState<React.ReactNode>(() => {
if (children && side === 'left') return children if (children && side === 'left') return children
@ -71,7 +71,7 @@ const SideBar = ({ isHidden, side, children }: SideBarProps) => {
useEffect(() => { useEffect(() => {
isHidden(!visible) isHidden(!visible)
}, [visible, isHidden]) }, [visible])
// resize controller // resize controller
useEffect(() => { useEffect(() => {
@ -89,7 +89,7 @@ const SideBar = ({ isHidden, side, children }: SideBarProps) => {
return () => { return () => {
window.removeEventListener('resize', checkWindowSize); window.removeEventListener('resize', checkWindowSize);
} }
}, [visible, open, close, hideSizePx,]) }, [visible])
return ( return (
<div> <div>

View File

@ -20,7 +20,6 @@ const SelectedDayList = ({
const { recordingsStore: recStore } = useContext(Context) const { recordingsStore: recStore } = useContext(Context)
const camera = recStore.filteredCamera const camera = recStore.filteredCamera
const host = recStore.filteredHost const host = recStore.filteredHost
const playedItem = recStore.playedItem
const { data, isPending, isError, refetch } = useQuery({ const { data, isPending, isError, refetch } = useQuery({
queryKey: [frigateQueryKeys.getRecordingsSummary, recStore.filteredCamera?.id, day], queryKey: [frigateQueryKeys.getRecordingsSummary, recStore.filteredCamera?.id, day],
@ -41,7 +40,7 @@ const SelectedDayList = ({
if (isPending) return <CenterLoader /> if (isPending) return <CenterLoader />
if (isError) return <RetryErrorPage onRetry={handleRetry} /> if (isError) return <RetryErrorPage onRetry={handleRetry} />
if (!camera || !host) return <CenterLoader /> if (!camera || !host) return <Center><Text>Please select host or camera</Text></Center>
if (!data) return <Text>Not have response from server</Text> if (!data) return <Text>Not have response from server</Text>
const stringDay = dateToQueryString(day) const stringDay = dateToQueryString(day)