Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(auth): provider -> strategy,
setup
method, multiple tokens
BREAKING CHANGE: ## 1. refactor(auth): rename auth provider to strategy - term auth `provider` renamed to auth `strategy` to eliminate intersection with Angular providers - `NbDummyAuthProvider` renamed to `NbDummyAuthStrategy` - `NbEmailPassAuthProvider` renamed to `NbDefaultAuthStrategy` - `NbAbstractAuthProvider` renamed to `NbAuthStrategy` - `NbAuthModule.forRoot({ forms.login.provider })` changed to `NbAuthModule.forRoot({ forms.login.strategy })` ``` `NbAuthModule.forRoot({ forms: { login: { strategy: 'email', // provider -> strategy }, }, })` ``` ## 2. refactor(auth): rename config to options (to conform with the rest of the app) `NbDummyAuthStrategyOptions` & `NbDefaultAuthStrategyOptions` are now classes with default values. - NbAuthModule.forRoot now takes `options` instead of `config` for a strategies ``` NbAuthModule.forRoot({ strategies: { email: { service: NbEmailPassAuthStrategy, options: { // was `config` previously ... }, }, }, }), ``` ## 3. refactor(auth): pass strategies through special `setup` method Refactor strategies object to array and pass strategy options through `setup` method. Strategy name moved inside of options object. - Auth module options' `strategies` list changed from a key=>value object to an array. So now instead of ``` strategies: { email: { service: NbEmailPassAuthProvider, config: { ... } } } ``` we do this: ``` strategies: [ NbPasswordAuthStrategy.setup({ name: 'email', ... }), ] ``` This way we can type-check the configuration object for each strategy specified. ## 4. refactor(tokens): add ability to use multiple tokens this allows having multiple tokens registered in the app. For instance, `NbJWTAuthToken` for `NbPasswordAuthStrategy` and `NbOAuth2AuthToken` for `NbOAuth2AuthStrategy`, allowing to work with multiple strategies. - `NB_AUTH_TOKEN_CLASS` token is removed. Instead, we specify token class within strategy configuration: ``` @NgModule({ imports: [ // ... NbAuthModule.forRoot({ strategies: [ NbPasswordAuthStrategy.setup({ name: 'email', token: { class: NbAuthJWTToken, // <---- } }), ], }), ], }); ``` - token class must have a `NAME` static field specified - tokens are now stored as JSON string `{ name: 'token-name', value: 'token-value' }` - now Strategy returns `NbAuthToken` instance instead of raw value - setRaw method of `NbTokenStorage` and `NbTokenService` is removed - token must have a payload
- Loading branch information