diff --git a/CHANGELOG b/CHANGELOG index c24b8bb..7efc964 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 @@ -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 diff --git a/docs/USAGE.MD b/docs/USAGE.MD index cac0edb..ee3073f 100644 --- a/docs/USAGE.MD +++ b/docs/USAGE.MD @@ -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[]; }; } diff --git a/package-lock.json b/package-lock.json index c327508..53e985b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cincoders/cinnamon", - "version": "1.2.2", + "version": "1.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@cincoders/cinnamon", - "version": "1.2.2", + "version": "1.3.0", "license": "MIT", "dependencies": { "@emotion/react": "^11.9.3", diff --git a/package.json b/package.json index 3cc3613..17ff7f0 100644 --- a/package.json +++ b/package.json @@ -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 (https://cincoders.cin.ufpe.br)", diff --git a/src/lib-components/ForbiddenPage/index.tsx b/src/lib-components/ForbiddenPage/index.tsx index 6895c6a..0bcf093 100644 --- a/src/lib-components/ForbiddenPage/index.tsx +++ b/src/lib-components/ForbiddenPage/index.tsx @@ -14,6 +14,7 @@ import { export interface ForbiddenPageProps { auth?: AuthContextProps; + publicURL?: string; } interface Location { @@ -25,8 +26,9 @@ 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(); const navigate = useNavigate(); const location = useLocation() as Location; @@ -34,7 +36,7 @@ export const ForbiddenPage = ({ auth }: ForbiddenPageProps) => { if (location.state?.from !== undefined) { setFrom(location.state.from.pathname); } else { - navigate(process.env.PUBLIC_URL as To); + navigate(baseURL as To); } }, []); diff --git a/src/lib-components/PageWithAuth/index.tsx b/src/lib-components/PageWithAuth/index.tsx index d784cc9..01640d2 100644 --- a/src/lib-components/PageWithAuth/index.tsx +++ b/src/lib-components/PageWithAuth/index.tsx @@ -5,6 +5,7 @@ import { AuthContextProps } from 'react-oidc-context'; interface PageWithAuthProps extends PageProps { authProps: { auth: AuthContextProps; + publicURL?: string; permittedRoles: string[]; }; } @@ -21,7 +22,7 @@ export function PageWithAuth({ }: PageWithAuthProps) { const { auth, permittedRoles } = authProps; return ( - + { + const publicURL = props.publicURL ?? process.env.PUBLIC_URL; + const location = useLocation(); const { children, auth, permittedRoles } = props; const [waiting, setWaiting] = useState(true); @@ -84,7 +87,7 @@ export const RequireAuth = (props: AuthProps): React.ReactElement => { if (auth.isAuthenticated) { return (