Skip to content

Commit

Permalink
oidc auth is served
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayahhhmed committed Nov 4, 2023
1 parent 77265c4 commit 1b25d9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
16 changes: 9 additions & 7 deletions client/src/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Weak = styled('span')`
const Navbar: React.FC = () => {
const [currLogo, setCurrLogo] = useState(notanglesLogo);
const { term, termName, year } = useContext(AppContext);
const userData = {};
const userData: User = { zid: '' };
const [user, setUser] = useState(userData);
const theme = useTheme<ThemeType>();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
Expand All @@ -66,9 +66,9 @@ const Navbar: React.FC = () => {
console.log(userResponse);
if (userResponse !== '') {
console.log(userResponse);
setUser(JSON.parse(userResponse));
setUser({ zid: JSON.parse(userResponse) });
} else {
setUser({});
setUser({ zid: '' });
}
} catch (error) {
console.log(error);
Expand All @@ -91,11 +91,12 @@ const Navbar: React.FC = () => {
console.log(error);
}
window.location.replace('http://localhost:5173');
setUser({});
setUser({ zid: '' });
};
// https://stackoverflow.com/a/32108184/1098564
const isEmpty = (obj: Object) => {
return Object.keys(obj).length === 0 && obj.constructor === Object;
const isEmpty = (currUser: User) => {
return currUser.zid === '';
//return Object.keys(obj).length === 0 && obj.constructor === Object;
};

return (
Expand Down Expand Up @@ -127,13 +128,14 @@ const Navbar: React.FC = () => {
content={<Privacy />}
/>
<CustomModal title="Settings" showIcon={<SettingsIcon />} description={'Settings'} content={<Settings />} />

{isEmpty(user) ? (
<Button color="warning" onClick={login}>
Login
</Button>
) : (
<Button color="warning" onClick={logout}>
{user} Logout
{user.zid} Logout
</Button>
)}
</Toolbar>
Expand Down
11 changes: 0 additions & 11 deletions client/src/interfaces/Users.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
export interface User {
<<<<<<< HEAD
id_token?: string;
access_token?: string;
refresh_token?: string;
userinfo?: UserInfo;
}

export interface UserInfo {
name?: string;
=======
zid: string;
>>>>>>> NTGL-be-oidc-cleanup
}
1 change: 0 additions & 1 deletion server/src/auth/login.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class LoginGuard extends AuthGuard('oidc') {
async canActivate(context: ExecutionContext) {

const result = (await super.canActivate(context)) as boolean;
const request = context.switchToHttp().getRequest();
await super.logIn(request);
Expand Down

0 comments on commit 1b25d9d

Please sign in to comment.