-
Notifications
You must be signed in to change notification settings - Fork 479
Update readme based on internal redesign #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9017c4d
Update readme based on internal redesign
frederikprijck e584e2d
update
frederikprijck 14d0dd5
add coverage badge
frederikprijck 027c365
Add banner
frederikprijck 3f1e7d4
Avoid relative links
frederikprijck 06d780d
Use banner from CDN
frederikprijck 1f08891
Move API reference to API.md
frederikprijck e00d634
Add title to examples
frederikprijck c603f1f
update banner
frederikprijck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,80 @@ | ||
|
||
- [Using a Custom Options Factory Function](#using-a-custom-options-factory-function) | ||
- [Configuration for Ionic 2+](#configuration-for-ionic-2) | ||
|
||
## Using a Custom Options Factory Function | ||
|
||
In some cases, you may need to provide a custom factory function to properly handle your configuration options. This is the case if your `tokenGetter` function relies on a service or if you are using an asynchronous storage mechanism (like Ionic's `Storage`). | ||
|
||
Import the `JWT_OPTIONS` `InjectionToken` so that you can instruct it to use your custom factory function. | ||
|
||
Create a factory function and specify the options as you normally would if you were using `JwtModule.forRoot` directly. If you need to use a service in the function, list it as a parameter in the function and pass it in the `deps` array when you provide the function. | ||
|
||
```ts | ||
import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt'; | ||
import { TokenService } from './app.tokenservice'; | ||
|
||
// ... | ||
|
||
export function jwtOptionsFactory(tokenService) { | ||
return { | ||
tokenGetter: () => { | ||
return tokenService.getAsyncToken(); | ||
}, | ||
allowedDomains: ["example.com"] | ||
} | ||
} | ||
|
||
// ... | ||
|
||
@NgModule({ | ||
// ... | ||
imports: [ | ||
JwtModule.forRoot({ | ||
jwtOptionsProvider: { | ||
provide: JWT_OPTIONS, | ||
useFactory: jwtOptionsFactory, | ||
deps: [TokenService] | ||
} | ||
}) | ||
], | ||
providers: [TokenService] | ||
}) | ||
``` | ||
|
||
**Note:**: If a `jwtOptionsFactory` is defined, then `config` is ignored. _Both configuration alternatives can't be defined at the same time_. | ||
|
||
## Configuration for Ionic 2+ | ||
|
||
The custom factory function approach described above can be used to get a token asynchronously with Ionic's `Storage`. | ||
|
||
```ts | ||
import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt'; | ||
import { Storage } from '@ionic/storage'; | ||
|
||
export function jwtOptionsFactory(storage) { | ||
return { | ||
tokenGetter: () => { | ||
return storage.get('access_token'); | ||
}, | ||
allowedDomains: ["example.com"] | ||
} | ||
} | ||
|
||
// ... | ||
|
||
@NgModule({ | ||
// ... | ||
imports: [ | ||
JwtModule.forRoot({ | ||
jwtOptionsProvider: { | ||
provide: JWT_OPTIONS, | ||
useFactory: jwtOptionsFactory, | ||
deps: [Storage] | ||
} | ||
}) | ||
] | ||
}) | ||
``` | ||
|
||
**Note:**: If a `jwtOptionsFactory` is defined, then `config` is ignored. _Both configuration alternatives can't be defined at the same time_. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.