Skip to content
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

Miscellaneous fixes and tweaks #28

Merged
merged 8 commits into from
Aug 14, 2020
Merged

Miscellaneous fixes and tweaks #28

merged 8 commits into from
Aug 14, 2020

Conversation

stevehobbsdev
Copy link
Contributor

  • Default redirectUri to window.location.origin
  • Unwrap defer around handleRedirectCallback
  • Add wildcard support to http interceptor
  • Add example in readme for URL wildcard

@stevehobbsdev stevehobbsdev added the review:small Small review label Aug 12, 2020
README.md Outdated Show resolved Hide resolved
it('attach the access token when the configuration uri is a string with a wildcard', fakeAsync((
done
) => {
httpClient.get('/basic-api/startsWith?hello=world').subscribe(done);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the use of the wildcard does not have any impact on URLs with or without a query string. The query string should be ignored, not considered when trying to match the endpoint. The path is the only portion we should use to match. Maybe the tests are a bit confusing because all of them include a query string value.

We could improve that to give the right message. A few examples:

  • With a rule of '/api/photos' it will match only exact paths, like /api/photos and /api/photos/ (is there any difference between both?? I don't think so).
  • With a rule of '/api/photos*' it will match anything that starts with that, like /api/photos, /api/photos/, /api/photos/31, /api/photos/me/summer/2020.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests here with more representative URLs, and refactored out the assertion to a common function.

I updated the regex ones too, even though they're about to be removed in another PR.

// If the URL ends with an asterisk, match using startsWith.
if (
typeof value === 'string' &&
value.indexOf('*') === value.length - 1 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value.indexOf('*') === value.length - 1

If I recall correctly, indexOf will return -1 when it's not found. And value.length of an empty string is 0. So this line will evaluate to true. The previous one is true as well, because it's still a string, even if empty. And the one below I think it will 💥 when it tries to substring(0, -1).

Can we add a test for this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an empty string to the config, as well as putting in a guard for this function that exits early when value is falsy.

@@ -8,15 +8,20 @@ import { AuthGuard } from './auth.guard';
@NgModule()
export class AuthModule {
static forRoot(config: AuthConfig): ModuleWithProviders<AuthModule> {
const defaultedConfig: AuthConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we rename this to defaultConfig, defaultValues or even baseConfig or baseValues ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm not precious about the name.

@stevehobbsdev stevehobbsdev merged commit be26384 into master Aug 14, 2020
@stevehobbsdev stevehobbsdev deleted the misc-fixes branch August 14, 2020 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:small Small review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants