Skip to content

Instantly share code, notes, and snippets.

@ericyoung
Created March 22, 2020 03:09
Show Gist options
  • Select an option

  • Save ericyoung/50b06800fb9ce6e7630316a1e9a68921 to your computer and use it in GitHub Desktop.

Select an option

Save ericyoung/50b06800fb9ce6e7630316a1e9a68921 to your computer and use it in GitHub Desktop.
Jekyll + Netlify
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