Skip to content

Commit

Permalink
docs: event remaining session duration time (#69)
Browse files Browse the repository at this point in the history
* docs: event remaining session duration time

Signed-off-by: David Dal Busco <[email protected]>

* docs: review post-install

Signed-off-by: David Dal Busco <[email protected]>

* docs: review event description

Signed-off-by: David Dal Busco <[email protected]>

---------

Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker authored Dec 2, 2023
1 parent 4f644b2 commit 8c88f4e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/build/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ To do so, you can follow these steps:

```json
{
"postinstall": "rsync -aqz node_modules/@junobuild/core/dist/workers/*.js public/workers/"
"scripts": {
"postinstall": "node -e \"require('fs').cpSync('node_modules/@junobuild/core/dist/workers/', './static/workers', {recursive: true});\""
}
}
```

Once configured, run `npm run postinstall` manually to trigger the initial copy. Every time you run `npm ci`, the post-install target will execute, ensuring the worker is copied.

2. Enable the option when you initialize Juno:

```javascript
Expand All @@ -169,15 +173,23 @@ await initJuno({
});
```

The `auth` option can accept either `true`, which will default to using a worker located at `https://yourapp/workers/auth.worker.js, or a custom `string` to provide your own URL.
The `auth` option can accept either `true`, which will default to using a worker located at https://yourapp/workers/auth.worker.js, or a custom `string` to provide your own URL.

When the session expires, it will be terminated with a standard [sign-out](#sign-out). Additionally, an informational event called `junoSignOutAuthTimer` will be thrown at the `document` level. This event is optional and can be used, for example, to display a warning to your users.
When the session expires, it will automatically be terminated with a standard [sign-out](#sign-out). Additionally, an event called `junoSignOutAuthTimer` will be thrown at the `document` level. This event can be used, for example, to display a warning to your users or if you wish to reload the window.

```javascript
document.addEventListener("junoSignOutAuthTimer", () => {
// Display an information to your users
}), {passive: true});
```

The worker also emits an event named `junoDelegationRemainingTime`, which provides the remaining duration in milliseconds of the authentication delegation. This can be useful if you want to display to your users how much time remains in their active session.

```javascript
document.addEventListener("junoDelegationRemainingTime", ({detail: remainingTime}) => {
// Display the remaining session duration to your users
}), {passive: true});
```

[Internet Identity]: ../terminology.md#internet-identity
[NFID]: ../terminology.md#nfid

0 comments on commit 8c88f4e

Please sign in to comment.