File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
components/authentication Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { useEffect , useState } from 'react' ;
3+ import { Amplify , Auth } from 'aws-amplify' ;
4+ import '@aws-amplify/ui-react/styles.css' ;
5+ import awsExports from '../../aws-exports' ;
6+ Amplify . configure ( awsExports ) ;
7+
8+ async function fetchUserIsTrusted ( setUserIsTrusted ) {
9+ const { accessToken} = await Auth . currentSession ( ) ;
10+ const cognitogroups = accessToken . payload [ 'cognito:groups' ] ;
11+ setUserIsTrusted ( cognitogroups . includes ( 'trusted' ) !== - 1 ) ;
12+ }
13+
14+ function PageContent ( props ) {
15+ return < props . content />
16+ }
17+
18+ function InjectPrivilegedContent ( props ) {
19+ // when calling this function, pass a prop called 'content' with your markdown payload
20+ const [ userIsTrusted , setUserIsTrusted ] = useState ( false ) ;
21+ useEffect ( ( ) => {
22+ fetchUserIsTrusted ( setUserIsTrusted ) ;
23+ } , [ ] ) ;
24+
25+ if ( userIsTrusted ) {
26+ return < PageContent content = { props . content } />
27+ } else {
28+ return null ;
29+ }
30+ } ;
31+
32+ export default InjectPrivilegedContent ;
You can’t perform that action at this time.
0 commit comments