Skip to content

Commit

Permalink
feat: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 3, 2024
1 parent f316a7a commit 6bec650
Show file tree
Hide file tree
Showing 32 changed files with 2,070 additions and 3,600 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.md
107 changes: 1 addition & 106 deletions content/docs/auth/session_guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,109 +532,4 @@ router
Finally, you can configure the redirect route for the logged-in users inside the `./app/middleware/guest_middleware.ts` file.

## Events

The session guard emits the following events using the emitter service.

### session_auth\:credentials_verified

The event is emitted after the credentials have been successfully verified using the `guard.attempt` method.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:credentials_verified', (event) => {
console.log(event.uid)
console.log(event.user)
})
```

### session_auth\:login_attempted

The event is emitter once the `auth.login` method is called directly or internally by the session guard.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:login_attempted', (event) => {
console.log(event.user)
})
```

### session_auth\:login_failed

The event is emitted when unable to login the user.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:login_failed', (event) => {
console.log(event.error)
console.log(event.user) // User | null
})
```

### session_auth\:login_succeeded

The event is emitted when the user has been logged in successfully.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:login_succeeded', (event) => {
console.log(event.sessionId)
console.log(event.user)
console.log(event.rememberMeToken) // (if created one)
})
```

### session_auth\:authentication_attempted

The event is emitted when the authentication is attempted using the `guard.authenticate` method. The `auth` middleware calls this method under the hood.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:authentication_attempted', (event) => {
console.log(event.sessionId)
})
```

### session_auth\:authentication_succeeded

The event is emitted when the authentication is successful.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:authentication_succeeded', (event) => {
console.log(event.sessionId)
console.log(event.user)
console.log(event.rememberMeToken) // if authenticated using token
})
```

### session_auth\:authentication_failed

The event is emitted when the authentication has failed.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:authentication_failed', (event) => {
console.log(event.sessionId)
console.log(event.error)
})
```

### session_auth\:logged_out

The event is emitted when the `guard.logout` method completes successfully.

```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('session_auth:logged_out', (event) => {
console.log(event.sessionId)
console.log(event.user) // User | null
})
```
Please check the [events reference guide](../reference/events.md#session_authcredentials_verified) to view the list of available events emitted by the Auth package.
41 changes: 30 additions & 11 deletions content/docs/database/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ Install the package from the npm packages registry using one of the following co

```sh
// title: npm
npm i @adonisjs/redis@next
npm i @adonisjs/redis
```

```sh
// title: yarn
yarn add @adonisjs/redis@next
yarn add @adonisjs/redis
```

```sh
// title: pnpm
pnpm add @adonisjs/redis@next
pnpm add @adonisjs/redis
```

:::
Expand Down Expand Up @@ -61,6 +61,8 @@ node ace configure @adonisjs/redis

The configuration for the Redis package is stored inside the `config/redis.ts` file.

See also: [Config file stub](https://github.com/adonisjs/redis/blob/next/stubs/config/redis.stub)

```ts
import env from '#start/env'
import { defineConfig } from '@adonisjs/redis'
Expand Down Expand Up @@ -119,20 +121,37 @@ The `@adonisjs/redis` package will create a [cluster connection](https://github.
const redisConfig = defineConfig({
connections: {
main: {
// highlight-start
clusters: [
{
port: 6380,
host: '127.0.0.1',
},
{
port: 6381,
host: '127.0.0.1',
},
{ host: '127.0.0.1', port: 6380 },
{ host: '127.0.0.1', port: 6381 },
],
clusterOptions: {
scaleReads: 'slave',
slotsRefreshTimeout: 10 * 1000,
},
// highlight-end
},
},
})
```

### Configuring sentinels
You can configure a redis connection to use sentinels by defining an array of sentinel nodes within the connection config. For example:

See also: [IORedis docs on Sentinels config](https://github.com/redis/ioredis?tab=readme-ov-file#sentinel)

```ts
const redisConfig = defineConfig({
connections: {
main: {
// highlight-start
sentinels: [
{ host: 'localhost', port: 26379 },
{ host: 'localhost', port: 26380 },
],
name: 'mymaster',
// highlight-end
},
},
})
Expand Down
42 changes: 36 additions & 6 deletions content/docs/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@
"contentPath": "./fundamentals/service_providers.md",
"category": "Fundamentals"
},
{
"permalink": "fundamentals/config-providers",
"title": "Config providers",
"contentPath": "./fundamentals/config_providers.md",
"category": "Fundamentals"
},
{
"permalink": "fundamentals/async-local-storage",
"title": "Async local storage",
Expand Down Expand Up @@ -315,12 +321,6 @@
"contentPath": "./digging_deeper/emitter.md",
"category": "Digging Deeper"
},
{
"permalink": "helpers",
"title": "Helpers",
"contentPath": "./digging_deeper/helpers.md",
"category": "Digging Deeper"
},
{
"permalink": "logger",
"title": "Logger",
Expand Down Expand Up @@ -417,5 +417,35 @@
"title": "REPL",
"contentPath": "./ace/repl.md",
"category": "Ace command line"
},
{
"permalink": "reference/commands",
"title": "Commands",
"contentPath": "./reference/commands.md",
"category": "Reference"
},
{
"permalink": "reference/edge",
"title": "Edge helpers and tags",
"contentPath": "./reference/edge.md",
"category": "Reference"
},
{
"permalink": "reference/events",
"title": "Events",
"contentPath": "./reference/events.md",
"category": "Reference"
},
{
"permalink": "reference/exceptions",
"title": "Exceptions",
"contentPath": "./reference/exceptions.md",
"category": "Reference"
},
{
"permalink": "reference/helpers",
"title": "Helpers",
"contentPath": "./reference/helpers.md",
"category": "Reference"
}
]
63 changes: 49 additions & 14 deletions content/docs/digging_deeper/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,62 @@ Bouncer is not an implementation of RBAC or ACL. Instead, it provides a low-leve

Install the package from the npm packages registry using one of the following commands.

:::codegroup

```sh
// title: npm
npm i @adonisjs/bouncer
```

```sh
// title: yarn
yarn add @adonisjs/bouncer
```

```sh
npm i @adonisjs/bouncer@next
// title: pnpm
pnpm add @adonisjs/bouncer
```

Once done, you must run the following command to configure the session package.
:::


Once done, you must run the following command to configure the bouncer package.

```sh
node ace configure @adonisjs/bouncer
```

:::disclosure{title="See steps performed by the configure command"}

1. Registers the following service provider inside the `adonisrc.ts` file.

```ts
{
providers: [
// ...other providers
() => import('@adonisjs/bouncer/bouncer_provider')
]
}
```

2. Creates the `app/abilities/main.ts` file to define and export abilities.

3. Creates the `app/policies/main.ts` file to export all policies as a collection.

3. Creates `initialize_bouncer_middleware` inside the `middleware` directory.

4. Register the following middleware inside the `start/kernel.ts` file.

```ts
router.use([
() => import('#middleware/initialize_bouncer_middleware')
])
```

:::


## Defining abilities

Abilities are JavaScript functions usually written inside the `./app/abilities/main.ts` file. You may export multiple abilities from this file.
Expand Down Expand Up @@ -612,15 +658,4 @@ These tags accepts the `ability` name or the `policy.method` name as the first p
```
## Events
Bouncer emits the `authorization:finished` event after the authorization check has been performed. The event payload includes the final response you may inspect to know the status of the check.
```ts
import emitter from '@adonisjs/core/services/emitter'

emitter.on('authorization:finished', (event) => {
console.log(event.user)
console.log(event.response)
console.log(event.parameters)
console.log(event.action)
})
```
Please check the [events reference guide](../reference/events.md#authorizationfinished) to view the list of events dispatched by the `@adonisjs/bouncer` package.
Loading

0 comments on commit 6bec650

Please sign in to comment.