From 370d95b1737ef81fbabf0944e2a0c6c3c5ed60c8 Mon Sep 17 00:00:00 2001 From: Fredrik Monsen Date: Fri, 13 Sep 2024 13:06:44 +0200 Subject: [PATCH] fix lint errors and warnings --- src/app/AuthProvider.tsx | 27 ++++++++++++++------------- src/app/api/auth/refresh/route.ts | 4 ++-- src/app/api/auth/signout/route.ts | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/app/AuthProvider.tsx b/src/app/AuthProvider.tsx index ac29295..bdc2b4e 100644 --- a/src/app/AuthProvider.tsx +++ b/src/app/AuthProvider.tsx @@ -24,6 +24,18 @@ export const AuthProvider = ({children}: { children: React.ReactNode }) => { const [user, setUser] = useState(); const [intervalId, setIntervalId] = useState(); + const handleNotAuthenticated = useCallback(() => { + setAuthenticated(false); + setUser(undefined); + if (intervalId) { + clearInterval(intervalId); + } + const currentUrl = window.location.href; + router.push( + `${keycloakConfig.url}/realms/${keycloakConfig.realm}/protocol/openid-connect/auth` + + `?client_id=${keycloakConfig.clientId}&redirect_uri=${currentUrl}&response_type=code&scope=openid`); + }, [intervalId, router]); + useEffect(() => { const codeInParams = new URLSearchParams(window.location.search).get('code'); if (codeInParams) { @@ -43,7 +55,8 @@ export const AuthProvider = ({children}: { children: React.ReactNode }) => { `${keycloakConfig.url}/realms/${keycloakConfig.realm}/protocol/openid-connect/auth` + `?client_id=${keycloakConfig.clientId}&redirect_uri=${currentUrl}&response_type=code&scope=openid`); } - }, []); + + }, [handleNotAuthenticated, router, user]); const handleIsAuthenticated = (newUser: User) => { if (newUser) { @@ -52,18 +65,6 @@ export const AuthProvider = ({children}: { children: React.ReactNode }) => { } }; - const handleNotAuthenticated = useCallback(() => { - setAuthenticated(false); - setUser(undefined); - if (intervalId) { - clearInterval(intervalId); - } - const currentUrl = window.location.href; - router.push( - `${keycloakConfig.url}/realms/${keycloakConfig.realm}/protocol/openid-connect/auth` + - `?client_id=${keycloakConfig.clientId}&redirect_uri=${currentUrl}&response_type=code&scope=openid`); - }, [intervalId, router]); - const refreshToken = useCallback(async () => { return refresh(); }, []); diff --git a/src/app/api/auth/refresh/route.ts b/src/app/api/auth/refresh/route.ts index ee5f9ba..dd6737f 100644 --- a/src/app/api/auth/refresh/route.ts +++ b/src/app/api/auth/refresh/route.ts @@ -1,8 +1,8 @@ -import {NextRequest, NextResponse} from 'next/server'; +import {NextResponse} from 'next/server'; import {User, UserToken} from '@/models/UserToken'; import {getRefreshToken, setUserCookie} from '@/utils/cookieUtils'; -export async function POST(req: NextRequest) { +export async function POST() { const refreshToken = getRefreshToken(); if (!refreshToken) { return NextResponse.json({error: 'No user token found'}, {status: 401}); diff --git a/src/app/api/auth/signout/route.ts b/src/app/api/auth/signout/route.ts index a18104c..a7fe8ba 100644 --- a/src/app/api/auth/signout/route.ts +++ b/src/app/api/auth/signout/route.ts @@ -1,7 +1,7 @@ -import {NextRequest, NextResponse} from 'next/server'; +import {NextResponse} from 'next/server'; import {deleteUserToken, getRefreshToken} from '@/utils/cookieUtils'; -export async function POST(req: NextRequest) { +export async function POST() { const refreshToken = getRefreshToken(); if (!refreshToken) { return NextResponse.json({error: 'No user token found'}, {status: 401});