Skip to content

Commit

Permalink
Merge pull request #101 from CinCoders/develop
Browse files Browse the repository at this point in the history
Version 1.3.0
  • Loading branch information
dcruzb authored Mar 13, 2024
2 parents 2324216 + 9ae93a8 commit 2cacc5b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.0] - 2024-03-13

### Added

- [RequireAuth] Now PUBLIC_URL is a prop, with fallback to process.env.PUBLIC_URL

## [1.2.1] - 2024-02-22

### Added
Expand Down Expand Up @@ -150,7 +156,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Empty SideMenu
- Issue template

[unreleased]: https://github.com/CinCoders/cinnamon/compare/version/v1.2.1...develop
[unreleased]: https://github.com/CinCoders/cinnamon/compare/version/v1.3.0...develop
[1.3.0]: https://github.com/CinCoders/cinnamon/compare/version/v1.2.1...version/v1.3.0
[1.2.1]: https://github.com/CinCoders/cinnamon/compare/version/v1.2.0...version/v1.2.1
[1.2.0]: https://github.com/CinCoders/cinnamon/compare/version/v1.1.0...version/v1.2.0
[1.1.0]: https://github.com/CinCoders/cinnamon/compare/version/v1.0.3...version/v1.1.0
Expand Down
8 changes: 4 additions & 4 deletions docs/USAGE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ A base page component with authentication using keycloak.
| **haveToast** | Boolean | No | none | Enable the usage of a custom toast from cinnamon package, inside the page component |
| **createNavbarContext** | Boolean | Yes | none | Enable the usage of custom hook useNavbar, to change navbar props dinamically |
| **components** | Object | No | none | An object that accepts a custom navbar, footer or toastContainer to override these default components |
| **auth** | Object | Yes | none | An object that accepts a keycloak instance, initialized flag and roles to have access |
| **auth** | Object | Yes | none | An object that accepts an authContext, publicURL and roles to have access |

### Interface of props

```typescript
interface PageWithAuthProps extends PageProps {
auth: {
keycloak: Keycloak;
initialized: boolean;
authProps: {
auth: AuthContextProps;
publicURL?: string;
permittedRoles: string[];
};
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cincoders/cinnamon",
"version": "1.2.2",
"version": "1.3.0",
"description": "A collection components for standardized system appearance and functionality, easing development in web applications.",
"license": "MIT",
"author": "CInCoders <[email protected]> (https://cincoders.cin.ufpe.br)",
Expand Down
6 changes: 4 additions & 2 deletions src/lib-components/ForbiddenPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

export interface ForbiddenPageProps {
auth?: AuthContextProps;
publicURL?: string;
}

interface Location {
Expand All @@ -25,16 +26,17 @@ interface Location {
};
}

export const ForbiddenPage = ({ auth }: ForbiddenPageProps) => {
export const ForbiddenPage = ({ auth, publicURL }: ForbiddenPageProps) => {
const email = auth?.user?.profile.email;
const baseURL = publicURL ?? process.env.PUBLIC_URL;
const [from, setFrom] = useState<string>();
const navigate = useNavigate();
const location = useLocation() as Location;
useEffect(() => {
if (location.state?.from !== undefined) {
setFrom(location.state.from.pathname);
} else {
navigate(process.env.PUBLIC_URL as To);
navigate(baseURL as To);
}
}, []);

Expand Down
3 changes: 2 additions & 1 deletion src/lib-components/PageWithAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AuthContextProps } from 'react-oidc-context';
interface PageWithAuthProps extends PageProps {
authProps: {
auth: AuthContextProps;
publicURL?: string;
permittedRoles: string[];
};
}
Expand All @@ -21,7 +22,7 @@ export function PageWithAuth({
}: PageWithAuthProps) {
const { auth, permittedRoles } = authProps;
return (
<RequireAuth auth={auth} permittedRoles={permittedRoles}>
<RequireAuth auth={auth} permittedRoles={permittedRoles} publicURL={authProps.publicURL}>
<Page
navbar={navbar}
footer={footer}
Expand Down
5 changes: 4 additions & 1 deletion src/lib-components/RequireAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import { KeycloakPayload, jwtDecode } from '@/utils/authUtils';
interface AuthProps {
auth: AuthContextProps;
permittedRoles: string[];
publicURL?: string;
children: JSX.Element;
}

export const RequireAuth = (props: AuthProps): React.ReactElement => {
const publicURL = props.publicURL ?? process.env.PUBLIC_URL;

const location = useLocation();
const { children, auth, permittedRoles } = props;
const [waiting, setWaiting] = useState(true);
Expand Down Expand Up @@ -84,7 +87,7 @@ export const RequireAuth = (props: AuthProps): React.ReactElement => {
if (auth.isAuthenticated) {
return (
<Navigate
to={`${process.env.PUBLIC_URL}/forbidden`}
to={`${publicURL}/forbidden`}
replace
state={{ from: location }}
/>
Expand Down

0 comments on commit 2cacc5b

Please sign in to comment.