brohlson / gatsby-plugin-anchor-links

⚓ Gatsby plugin for using smooth scroll anchor links with a Gatsby Link component
https://www.npmjs.com/package/gatsby-plugin-anchor-links
MIT License
68 stars 22 forks source link

Hash params crashing application #4

Closed mbwatson closed 4 years ago

mbwatson commented 4 years ago

I'm attempting to integrate a Gatsby app with an external authentication tool that uses OIDC. As is typical, I link over to the external provider's login page, enter credentials, log in, then that page authenticates the user, and sends them back via the redirect URI, which contains a bunch of hash parameters, token_type, id_token, etc.

Because they're coming in as hash parameters (https://domain.com/page/#token_type=Bearer&id_token=eyJ...Y1st5OQ), and not query parameters (https://domain.com/page/?token_type=Bearer&id_token=eyJ...Y1st5OQ), there is a conflict with this plugin.

It seems to want to check the DOM for an element with an ID given by the hash string appended to the redirect URL. The error

Document.querySelector: '#token_type=Bearer&id_token=eyJ...Y1st5OQ' is not a valid selector.

is thrown, and the application crashes.

Could this plugin safely navigate this error?

brohlson commented 4 years ago

Thanks for the report @mbwatson - something I didn't consider - big oversight! I'll put up a patch over the weekend.

mbwatson commented 4 years ago

That's great! Thanks for your prompt response, too!

I really love having this plugin, so please let me know if I can assist in any way.

brohlson commented 4 years ago

@mbwatson - Just released 1.1.1 which checks for a valid selector before running the scroller. Thanks for catching it mate.

mbwatson commented 4 years ago

@brohlson Awesome, the update prevents crashing. I do, however, see a warning in the console: Anchor Links plugin attempted to scroll to an invalid hash on route change if that's a concern to address.

brohlson commented 4 years ago

@brohlson Awesome, the update prevents crashing. I do, however, see a warning in the console: Anchor Links plugin attempted to scroll to an invalid hash on route change if that's a concern to address.

I added this. I think it's a pretty valid warning considering how edgy this case feels.