Skip to content

Commit 35ec583

Browse files
author
Rhys Faultless
committed
For content added to public page, based on Auth.
1 parent bfc1847 commit 35ec583

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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;

0 commit comments

Comments
 (0)