Skip to content

Commit

Permalink
fix lint errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikmonsen committed Sep 13, 2024
1 parent 7b7e7e4 commit 370d95b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
27 changes: 14 additions & 13 deletions src/app/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export const AuthProvider = ({children}: { children: React.ReactNode }) => {
const [user, setUser] = useState<User>();
const [intervalId, setIntervalId] = useState<number>();

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) {
Expand All @@ -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) {
Expand All @@ -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();
}, []);
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/auth/refresh/route.ts
Original file line number Diff line number Diff line change
@@ -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});
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/auth/signout/route.ts
Original file line number Diff line number Diff line change
@@ -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});
Expand Down

0 comments on commit 370d95b

Please sign in to comment.