-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
/* | ||
* adonis-session | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
const path = require('path') | ||
|
||
module.exports = async function (cli) { | ||
try { | ||
await cli.makeConfig('session.js', path.join(__dirname, './templates/config.mustache')) | ||
} catch (error) { | ||
// ignore if session.js already exists | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Registering provider | ||
|
||
Make sure to register the provider before you can make use of sessions. The providers are registered inside `start/app.js` file. | ||
|
||
```js | ||
const providers = [ | ||
'@adonisjs/session/providers/SessionProvider' | ||
] | ||
``` | ||
|
||
## Registering middleware | ||
|
||
The next thing you should do is register the global middleware inside `start/kernel.js` file. | ||
|
||
```js | ||
const globalMiddleware = [ | ||
'Adonis/Middleware/Session' | ||
] | ||
``` | ||
|
||
## Using session | ||
|
||
Once done with provider and middleware registeration, you can make use of the session by grabbing an instance from the HTTP request context. | ||
|
||
```js | ||
Route.get('/', async ({ session }) => { | ||
session.get('username') | ||
session.put('username', 'virk') | ||
}) | ||
``` | ||
|
||
## Config | ||
|
||
You can find the configuration inside `config/session.js` file. Feel free to tweak it as per your needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.