Skip to content

Commit

Permalink
removed roles check
Browse files Browse the repository at this point in the history
  • Loading branch information
chelsea-EYDS committed Dec 19, 2023
1 parent 76853c0 commit 5d7f27b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
19 changes: 5 additions & 14 deletions backend/src/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
UnauthorizedException,
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import jwt, { JwtPayload } from 'jsonwebtoken';
import jwt from 'jsonwebtoken';

import { AUTH_CLIENT, AUTH_SERVER, AUTH_REALM } from './const';
import { Role, Token } from './interface';
import { AUTH_SERVER, AUTH_REALM } from './const';
import { Token } from './interface';
import { Metadata } from './metadata';

@Injectable()
Expand All @@ -20,6 +20,7 @@ export class AuthGuard implements CanActivate {
Metadata.IS_PUBLIC,
[context.getHandler(), context.getClass()],
);

if (isPublic) {
return true;
}
Expand All @@ -36,8 +37,7 @@ export class AuthGuard implements CanActivate {
throw new UnauthorizedException();
}
try {
const payload = this.validateToken(token);
this.setRequestRoles(payload, request);
this.validateToken(token);
} catch {
throw new UnauthorizedException();
}
Expand Down Expand Up @@ -76,13 +76,4 @@ export class AuthGuard implements CanActivate {
//YODO check expiry
return payload;
}

setRequestRoles(payload: JwtPayload, request: Request): Role[] {
if (payload.resource_access?.[AUTH_CLIENT].roles) {
request['roles'] = payload.resource_access?.[AUTH_CLIENT].roles;
} else {
request['roles'] = [];
}
return request['roles'];
}
}
4 changes: 1 addition & 3 deletions frontend/src/hooks/useGetHealth.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { getAppHealth, getRole, getAuth } from '../services/health';
import { getAppHealth, getAuth } from '../services/health';

interface Health {
status?: string;
Expand All @@ -12,7 +12,6 @@ export const useGetHealth = () => {
const [appHealth, setAppHealth] = useState<Health>();
const [dbHealth, setDBHealth] = useState<Health>();
const [authRoutes, setAuthRoutes] = useState<boolean>(false);
const [roles, setRoles] = useState<string[]>([]);

useEffect(() => {
(async () => {
Expand Down Expand Up @@ -48,7 +47,6 @@ export const useGetHealth = () => {
return {
appHealth,
dbHealth,
roles,
authRoutes,
};
};
2 changes: 1 addition & 1 deletion frontend/src/pages/AppHealth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logout } from '../services/keycloak';

//TODO remove - this is just for development
const AppHealth = () => {
const { appHealth, dbHealth, roles, authRoutes } = useGetHealth();
const { appHealth, dbHealth, authRoutes } = useGetHealth();

return (
<div className="flex flex-col justify-around h-auto">
Expand Down

0 comments on commit 5d7f27b

Please sign in to comment.