Updated README for members layer2 SDK

This commit is contained in:
Fabien O'Carroll 2018-11-14 15:12:59 +07:00 committed by GitHub
parent 51a5e53c06
commit 37e8d5b670

View File

@ -13,12 +13,16 @@ or
### As a drop in script:
This will attack a `Members` object to the window, with a `getToken` method.
This will automatically hide and show the elements with `data-members-signin` and `data-members-signout` attributes.
It will automatically hide and show the elements with `data-members-signin` and `data-members-signout` attributes
It will set a js cookie called `member` with the token, on the `/` path and keep it in sync with the state of the users loggedin status
It will also reload the page on login/logout, so you are able to read the cookie serverside, and do any content rendering there.
```html
<script src="members-layer2.dropin.js"></script>
<script>
fetch('/ghost/api/v2/content/posts/<id>', { credentials: 'same-origin' });
</script>
```
### As a library
@ -26,18 +30,20 @@ It will automatically hide and show the elements with `data-members-signin` and
```html
<script src="members-layer2.lib.js"></script>
<script>
Members.init(); // Sets up binding the elements to the login/logout state
Members.init(); // Sets up binding the elements to the login/logout state and member cookie
Members.getToken();
fetch('/ghost/api/v2/content/posts/<id>', { credentials: 'same-origin' });
</script>
```
#### Or with a module loader
```javascript
const Members = require('@tryghost/members-layer2');
Members.init(); // Sets up binding the elements to the login/logout state
Members.getToken();
fetch('/ghost/api/v2/content/posts/<id>', { credentials: 'same-origin' });
```