Skip to content

Commit f8bf021

Browse files
committed
Review README
1 parent c89953f commit f8bf021

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

README.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,36 @@ If you are targeting mobile audiences, it's recommended that you add:
4242

4343
## API
4444

45-
### new Auth0Lock(clientID, domain, options, callback)
45+
### new Auth0Lock(clientID, domain, options)
4646

4747
Initializes a new instance of `Auth0Lock` configured with your application `clientID` and your account's `domain` at [Auth0](https://manage.auth0.com/). You can find this information at your [application settings](https://manage.auth0.com/#/applications).
4848

4949
- **clientId {String}**: Your application _clientId_ in Auth0.
5050
- **domain {String}**: Your Auth0 _domain_. Usually _your-account.auth0.com_.
5151
- **options {Object}**: Allows to customize the dialog's appearance and behavior. See [below](#customization) for the details.
52-
- **callback {function}**: Will be invoked after an attempt to authenticate the user.
5352

5453
#### Example
5554

5655
```js
5756
var clientId = "YOUR_AUTH0_APP_CLIENTID";
5857
var domain = "YOUR_DOMAIN_AT.auth0.com";
59-
var lock = new Auth0Lock(clientId, domain, {},
60-
function(error, result) {
61-
// Will always be executed. Execution will happen on a later frame, so the
62-
// `lock` variable and everything will be available on scope.
58+
var lock = new Auth0Lock(clientId, domain);
59+
60+
lock.on("authenticated", function(authResult) {
61+
lock.getProfile(authResult.idToken, function(error, profile) {
6362
if (error) {
6463
// Handle error
64+
return;
6565
}
6666

67-
if (result) {
68-
// We need to check for a result, if there was an error `result` will be
69-
// undefined.
70-
71-
// store the token and profile in local storage (or wherever you choose)
72-
localStorage.setItem('idToken', result.idToken);
67+
localStorage.setItem("idToken", authResult.idToken);
68+
localStorage.setItem("profile", JSON.stringify(profile));
7369

74-
// Optionally fetch the profile
75-
lock.getProfile(result.idToken, function(error, profile) {
76-
if (error) {
77-
// Handle error
78-
}
79-
80-
localStorage.setItem('profile', JSON.stringify(profile));
81-
});
82-
}
70+
// Update DOM
71+
});
8372
});
8473
```
8574

86-
8775
### getProfile(idToken, callback)
8876

8977
Once the user has logged in and you are in possesion of and id token, you can obtain the profile with `getProfile`.
@@ -94,13 +82,23 @@ Once the user has logged in and you are in possesion of and id token, you can ob
9482
#### Example
9583

9684
```js
97-
lock.getProfile(id_token, function(error, profile) {
85+
lock.getProfile(idToken, function(error, profile) {
9886
if (!error) {
9987
alert("hello " + profile.name);
10088
}
10189
});
10290
```
10391

92+
### on(event, callback)
93+
94+
Lock will emit events during its lifecycle.
95+
96+
- `show`: emitted when Lock is shown. Has no arguments.
97+
- `hide`: emitted when Lock is hidden. Has no arguments.
98+
- `unrecoverable_error`: emitted when there is an unrecoverable error, for instance when no connection is available. Has the error as the only argument.
99+
- `authenticated`: emitted after a successful authentication. Has the authentication result as the only argument.
100+
- `authorization_error`: emitted when authorization fails. Has error as the only argument.
101+
104102
### Customization
105103

106104
The appearance of the widget and the mechanics of authentication can be customized with an `options` object which has one or more of the following properties. Each method that opens the dialog can take an `options` object as its first argument.

0 commit comments

Comments
 (0)