I'm using React, recompose, and apollo GraphQL
I'm trying to create UI authorization (backend auth will be there as well) to allow users with a specific role to enter pages that only they authorized to enter. I'm going off of an article that I found helpful.
In the article, he uses static props. I need to pass props from a data query that I compose together with my Authorization component in an index.js file.
Currently my code looks like the following:
import React from 'react'
import { Redirect } from 'react-router-dom'
const Authorization = ({ props }) => allowAccess => MyComponent => {
const { viewer: { role } } = props.data
return (
( allowAccess.include(role) ) ? <MyComponent /> : <Redirect to="/" />
)
}
export default Authorization
In another file I created variables that hold roles that are allowed to access pages, same as the article referenced above:
export const admin = ['owner', 'admin']
export const user = ['owner', 'admin', 'user']
Then I import this file and my Auth into the file I define my routes. I do the same as the author did in the article and define the roles that will wrap a route component based on who is allowed to view the page:
const Admin = Authorization(admin)
const User = Authorization(user)
This is where I'm being thrown an error
What I think it happening is it's trying to find a graphql props on the array of user roles I'm passing instead of on Authorization.