2
0

abort-controller.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2002-2024 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. "use strict";
  17. const holder = {
  18. controller: new AbortController(),
  19. };
  20. /**
  21. * Returns a new AbortSignal to be used in the options for the registration and authentication ceremonies.
  22. * Aborts the existing AbortController if it exists, cancelling any existing ceremony.
  23. *
  24. * The authentication ceremony, when triggered with conditional mediation, shows a non-modal
  25. * interaction. If the user does not interact with the non-modal dialog, the existing ceremony MUST
  26. * be cancelled before initiating a new one, hence the need for a singleton AbortController.
  27. *
  28. * @returns {AbortSignal} a new, non-aborted AbortSignal
  29. */
  30. function newSignal() {
  31. if (!!holder.controller) {
  32. holder.controller.abort("Initiating new WebAuthN ceremony, cancelling current ceremony");
  33. }
  34. holder.controller = new AbortController();
  35. return holder.controller.signal;
  36. }
  37. export default {
  38. newSignal,
  39. };