Created
March 22, 2020 03:09
-
-
Save ericyoung/50b06800fb9ce6e7630316a1e9a68921 to your computer and use it in GitHub Desktop.
Jekyll + Netlify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. When enabling netlify identity and git-gateway, you can assign roles to the user, and even use roles as a store, such as "company:Bill Young Productions." | |
| 2. To protect a page, create a layout (_layouts/protected/admin.html) that inherits from default layout and protect the layout like this: | |
| --- | |
| layout: page | |
| role: admin | |
| --- | |
| <script type="text/javascript"> | |
| var allowed = user.app_metadata.roles.includes(page.role); | |
| if(!allowed) window.location.replace("/denied"); | |
| </script> | |
| Add netlify-identity-widget.js and auth.js to _includes/header.html. | |
| Auth.js should be: | |
| const auth = new GoTrue({ | |
| APIUrl: "https://vigorous-wescoff-d0ab76.netlify.com/.netlify/identity", | |
| audience: "", | |
| setCookie: false | |
| }); | |
| const user = auth.currentUser(); | |
| 3. You can insert the user name into a page via: <script>document.write(user.user_metadata.full_name);</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment