Skip to content

Commit

Permalink
Merge pull request #143 from RichDom2185/restore-min-to-ms
Browse files Browse the repository at this point in the history
Fix: documentation
  • Loading branch information
yordis authored Sep 17, 2023
2 parents 6757479 + 1d16719 commit aed1cc4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
### Breaking changes

* `Guardian.DB.Token.SweeperServer` becomes `Guardian.DB.Sweeper`
* `sweep_interval` option is no longer supported. Specify interval directly instead.
* Sweep intervals are now specified in milliseconds instead of minutes.

## v2.0.2

Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ config :guardian, Guardian.DB,
repo: MyApp.Repo, # Add your repository module
schema_name: "guardian_tokens", # default
token_types: ["refresh_token"], # store all token types if not set
sweep_interval: 60 # default: 60 minutes
```

To sweep expired tokens from your db you should add
`Guardian.DB.Token.SweeperServer` to your supervision tree.
`Guardian.DB.Sweeper` to your supervision tree.

```elixir
children = [
{Guardian.DB.Token.SweeperServer, []}
{Guardian.DB.Sweeper, [interval: 60 * 60 * 1000]} # 1 hour
]
```

Expand Down Expand Up @@ -173,8 +172,8 @@ approach to authentication!

### Create your own Repo

We created `Guardian.DB.Adapter` behaviour to allow creating other repositories for persisting JWT tokens.
You need to implement the `Guardian.DB.Adapter` behavior working with your preferred storage.
We created `Guardian.DB.Adapter` behaviour to allow creating other repositories for persisting JWT tokens.
You need to implement the `Guardian.DB.Adapter` behavior working with your preferred storage.

### Adapters

Expand Down
7 changes: 4 additions & 3 deletions lib/guardian/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ defmodule Guardian.DB do
* `prefix` - The schema prefix to use.
* `schema_name` - The name of the schema to use. Default "guardian_tokens".
* `sweep_interval` - The interval between db sweeps to remove old tokens.
Default 60 (minutes).
### Sweeper
In order to sweep your expired tokens from the db, you'll need to add
`Guardian.DB.Sweeper` to your supervision tree.
In your supervisor add it as a worker
* `interval` - The interval between db sweeps to remove old tokens, in
milliseconds. Defaults to 1 hour.
```elixir
worker(Guardian.DB.Sweeper, [interval: 60])
worker(Guardian.DB.Sweeper, [interval: 60 * 60 * 1000])
```
# Migration
Expand Down
7 changes: 6 additions & 1 deletion lib/guardian/db/sweeper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ defmodule Guardian.DB.Sweeper do
To leverage the automated Sweeper functionality update your project's Application
file to include the following child in your supervision tree:
* `interval` - The interval between db sweeps to remove old tokens, in
milliseconds. Defaults to 1 hour.
## Example
worker(Guardian.DB.Sweeper, [interval: 60])
```elixir
worker(Guardian.DB.Sweeper, [interval: 60 * 60 * 1000])
```
"""
use GenServer

Expand Down

0 comments on commit aed1cc4

Please sign in to comment.