Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
red-giant
dashboard
Merge requests
!53
Feature/authorization/curry
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/authorization/curry
feature/authorization/curry
into
dev
Overview
0
Commits
10
Pipelines
1
Changes
1
Merged
Defendi Alberto
requested to merge
feature/authorization/curry
into
dev
3 years ago
Overview
0
Commits
10
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Viewing commit
79f3c8b8
Prev
Next
Show latest version
1 file
+
4
−
3
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Verified
79f3c8b8
Curry funciton to accept roles before creating component.
· 79f3c8b8
Defendi Alberto
authored
3 years ago
src/components/Authorization/Authorization.tsx
+
4
−
3
Options
@@ -25,15 +25,16 @@ interface WithAuthProps {
@@ -25,15 +25,16 @@ interface WithAuthProps {
* This creates a "personal area" in the working implementation.
* This creates a "personal area" in the working implementation.
* @returns {FC<T>} wrapped component.
* @returns {FC<T>} wrapped component.
*/
*/
export
const
withAuthorization
=
<
T
extends
WithAuthProps
=
WithAuthProps
>
(
export
const
withAuthorization
=
(
allowedRoles
:
string
[])
=>
<
T
extends
WithAuthProps
=
WithAuthProps
>
(
WrappedComponent: React.ComponentType
<
T
>
,
WrappedComponent: React.ComponentType
<
T
>
,
): FC
<
T
>
=>
{
): FC
<
T
>
=>
{
// Creating the inner component. The calculated Props type here is the where the magic happens.
// Creating the inner component. The calculated Props type here is the where the magic happens.
const
ComponentWithAuthorization
:
FC
<
T
>
=
(
const
ComponentWithAuthorization
:
FC
<
T
>
=
(
props
:
Omit
<
T
,
keyof
WithAuthProps
>
,
props
:
Omit
<
T
,
keyof
WithAuthProps
>
,
)
=>
{
)
=>
{
const
{
allowedRoles
}
=
props
as
T
;
const
{
role
,
isAuth
}
=
useContext
(
AuthContext
);
const
{
role
,
isAuth
}
=
useContext
(
AuthContext
);
console
.
log
(
`ROLE
${
role
}
AUTH
${
isAuth
}
`
);
console
.
log
(
`ROLE
${
role
}
AUTH
${
isAuth
}
`
);
Loading