Sandbox default auth strategy
- Dominant language
- JavaScript
- Stars
- 14.8k
- Forks
- 1.4k
- Avg merge
- 22d 3h
- Merged PRs (30d)
- 1
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no
#### Context
* *node version*: v12.16.1
* *module version*: v20.0.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi
* *any other relevant information*: N/A
#### What problem are you trying to solve?
I want to sandbox the default strategy set in a plugin. Since `server.auth.strategy()` is sandboxed, it would make sense to sandbox `server.auth.default()` as well. In my case, I have 2 plugins, one for the API and the other is for the site renderer. The API has session strategy by default, but because `server.auth.default()` is not sandboxed, all the routes registered by the renderer have the same default strategy.
(There are of course several workarounds to this issue such as using `server.rules()` or set `auth: false` in the renderer, but I would like to see a more consistent sandboxing behaviour).
```js
const Api = {
name: 'api',
register(server) {
await server.register(Cookie);
server.auth.strategy('session', 'cookie', {});
server.auth.default('session');
}
};
const Renderer = {
name: 'renderer',
register(server) {
server.routes({ path: '/{p*}', method: 'GET', handler() {} }); // Uses session by default
}
};
function bootstrap() {
const server = new Hapi.Server();
await server.register(Api, Renderer);
}
bootstrap();
```
#### Do you have a new or modified API suggestion to solve the problem?
N/A
Contributor guide
Assessment
This issue has not been assessed yet.