Skip to content

Commit 5afbdf8

Browse files
committed
Reformat README and add
Also document netlifyIdentity.open(`login`)
1 parent 9fba227 commit 5afbdf8

File tree

1 file changed

+53
-37
lines changed

1 file changed

+53
-37
lines changed

README.md

+53-37
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
# Netlify Identity Widget
22

3-
A component used to authenticate with Netlify's Identity service. [Live demo](https://identity.netlify.com)
3+
A component used to authenticate with Netlify's Identity service.
4+
[Live demo](https://identity.netlify.com)
45

5-
For a lower level library to the underlying `GoTrue` API, see [gotrue-js](https://github.com/netlify/gotrue-js).
6+
For a lower level library to the underlying `GoTrue` API, see
7+
[gotrue-js](https://github.com/netlify/gotrue-js).
68

79
## What is Netlify Identity
8-
Netlify’s Identity service is a plug-and-play microservice for handling site functionalities like signups, logins, password recovery, user metadata, and roles. You can use it from single page apps instead of rolling your own, and integrate with any service that understands JSON Web Tokens (JWTs).
910

10-
Learn more about this service from this [blog post](https://www.netlify.com/blog/2017/09/07/introducing-built-in-identity-service-to-streamline-user-management/).
11+
Netlify’s Identity service is a plug-and-play microservice for handling site
12+
functionalities like signups, logins, password recovery, user metadata, and
13+
roles. You can use it from single page apps instead of rolling your own, and
14+
integrate with any service that understands JSON Web Tokens (JWTs).
15+
16+
Learn more about this service from this
17+
[blog post](https://www.netlify.com/blog/2017/09/07/introducing-built-in-identity-service-to-streamline-user-management/).
1118

1219
## Usage
1320

14-
Simply include the widget on your site, and things like invites, confirmation codes, etc, will start working.
21+
Simply include the widget on your site, and things like invites, confirmation
22+
codes, etc, will start working.
1523

1624
You can add controls for the widget with HTML:
1725

@@ -39,40 +47,42 @@ You can add controls for the widget with HTML:
3947
</html>
4048
```
4149

42-
The widget will automatically attach itself to the window object as `window.netlifyIdentity`.
50+
The widget will automatically attach itself to the window object as
51+
`window.netlifyIdentity`.
4352

4453
You can use this global object like this:
4554

4655
```js
47-
// open the modal
48-
netlifyIdentity.open()
56+
// open the modal
57+
netlifyIdentity.open();
4958

5059
// Get the current user:
5160
const user = netlifyIdentity.currentUser();
5261

5362
// Bind to events
54-
netlifyIdentity.on('init', user => console.log(user))
55-
netlifyIdentity.on('login', user => console.log(user))
56-
netlifyIdentity.on('logout', () => console.log("Logged out"))
57-
netlifyIdentity.on('error', err => console.error("Logged out"))
58-
netlifyIdentity.on('open', () => console.log("Widget opened"))
59-
netlifyIdentity.on('close', () => console.log("Widget closed"))
63+
netlifyIdentity.on("init", user => console.log(user));
64+
netlifyIdentity.on("login", user => console.log(user));
65+
netlifyIdentity.on("logout", () => console.log("Logged out"));
66+
netlifyIdentity.on("error", err => console.error("Logged out"));
67+
netlifyIdentity.on("open", () => console.log("Widget opened"));
68+
netlifyIdentity.on("close", () => console.log("Widget closed"));
6069

6170
// Close the modal
62-
loginModal.close()
71+
loginModal.close();
6372

6473
// Logout the user
6574
loginModal.logout();
6675
```
6776

6877
#### A note on script tag versioning
6978

70-
The `v1` in the above URL is not pinned to the major version of the module API, and will only reflect breaking changes in the
71-
markup API.
79+
The `v1` in the above URL is not pinned to the major version of the module API,
80+
and will only reflect breaking changes in the markup API.
7281

7382
### Module API
7483

75-
Netlify Identity Widget also has a [module api](https://www.npmjs.com/package/netlify-identity-widget):
84+
Netlify Identity Widget also has a
85+
[module api](https://www.npmjs.com/package/netlify-identity-widget):
7686

7787
```
7888
yarn add netlify-identity-widget
@@ -81,41 +91,46 @@ yarn add netlify-identity-widget
8191
Import or require as usual:
8292

8393
```js
84-
const netlifyIdentity = require("netlify-identity-widget")
94+
const netlifyIdentity = require("netlify-identity-widget");
8595

8696
netlifyIdentity.init({
87-
container: "#netlify-modal", // defaults to document.body,
97+
container: "#netlify-modal" // defaults to document.body,
8898
});
8999

90-
netlifyIdentity.open() // open the modal
100+
netlifyIdentity.open(); // open the modal
101+
netlifyIdentity.open("login"); // open the modal to the login tab
102+
netlifyIdentity.open("signup"); // open the modal to the signup tab
91103

92-
netlifyIdentity.on('init', user => console.log(user))
93-
netlifyIdentity.on('login', login => console.log(user))
94-
netlifyIdentity.on('logout', () => console.log("Logged out"))
95-
netlifyIdentity.on('error', err => console.error("Logged out"))
96-
netlifyIdentity.on('open', () => console.log("Widget opened"))
97-
netlifyIdentity.on('close', () => console.log("Widget closed"))
104+
netlifyIdentity.on("init", user => console.log(user));
105+
netlifyIdentity.on("login", login => console.log(user));
106+
netlifyIdentity.on("logout", () => console.log("Logged out"));
107+
netlifyIdentity.on("error", err => console.error("Logged out"));
108+
netlifyIdentity.on("open", () => console.log("Widget opened"));
109+
netlifyIdentity.on("close", () => console.log("Widget closed"));
98110

99111
// Close the modal
100-
identity.close()
112+
identity.close();
101113

102114
// Logout the user
103115
netlifyIdentity.logout();
104116

105117
// Access the underlying gotrue instance.
106118
// Note that doing things directly through gotrue brings a risk of getting out of
107119
// sync between your state and the widgets state.
108-
netlifyIdentity.gotrue
120+
netlifyIdentity.gotrue;
109121
```
110122

111123
## Localhost
112124

113-
When using the widget on localhost, it will prompt for your Netlify SiteURL the first time it is opened. Entering the siteURL populates the browser's localStorage.
125+
When using the widget on localhost, it will prompt for your Netlify SiteURL the
126+
first time it is opened. Entering the siteURL populates the browser's
127+
localStorage.
114128

115-
This allows the widget to know which instance of Netlify Identity it should communicate with with zero
116-
configuration.
129+
This allows the widget to know which instance of Netlify Identity it should
130+
communicate with with zero configuration.
117131

118-
E.g. If your Netlify site is served from the `olddvdscreensaver.com` domain name, enter the following when prompted by the widget when in development mode:
132+
E.g. If your Netlify site is served from the `olddvdscreensaver.com` domain
133+
name, enter the following when prompted by the widget when in development mode:
119134

120135
```
121136
https://olddvdscreensaver.com
@@ -125,11 +140,12 @@ https://olddvdscreensaver.com
125140

126141
## FAQ
127142

128-
- If you experience a 404 while testing the Netlify Identity Widget on a local environment, you can
129-
manually remove the netlifySiteURL from localStorage by doing the following in the console.
143+
* If you experience a 404 while testing the Netlify Identity Widget on a local
144+
environment, you can manually remove the netlifySiteURL from localStorage by
145+
doing the following in the console.
130146

131147
```js
132-
localStorage.removeItem("netlifySiteURL")
148+
localStorage.removeItem("netlifySiteURL");
133149
```
134150

135-
- See the `example` for how to integrate this widget with a react app.
151+
* See the `example` for how to integrate this widget with a react app.

0 commit comments

Comments
 (0)