WebauthnKeys.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div>
  3. <div class="mt-6">
  4. <h3 class="font-bold text-xl">
  5. Device Authentication (U2F)
  6. </h3>
  7. <div class="my-4 w-24 border-b-2 border-grey-200"></div>
  8. <p class="my-6">
  9. Webauthn Keys you have registered for 2nd factor authentication. To remove a key simply
  10. click the delete button next to it.
  11. </p>
  12. <div>
  13. <p class="mb-0" v-if="keys.length === 0">
  14. You have not registered any Webauthn Keys.
  15. </p>
  16. <div class="table w-full text-sm md:text-base" v-if="keys.length > 0">
  17. <div class="table-row">
  18. <div class="table-cell p-1 md:p-4 font-semibold">Name</div>
  19. <div class="table-cell p-1 md:p-4 font-semibold">Created</div>
  20. <div class="table-cell p-1 md:p-4 text-right">
  21. <a href="/webauthn/register" class="text-indigo-700">Add New Device</a>
  22. </div>
  23. </div>
  24. <div v-for="key in keys" :key="key.id" class="table-row even:bg-grey-50 odd:bg-white">
  25. <div class="table-cell p-1 md:p-4">{{ key.name }}</div>
  26. <div class="table-cell p-1 md:p-4">{{ key.created_at | timeAgo }}</div>
  27. <div class="table-cell p-1 md:p-4 text-right">
  28. <a
  29. class="text-red-500 font-bold cursor-pointer focus:outline-none"
  30. @click="showRemoveModal(key)"
  31. >
  32. Delete
  33. </a>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <Modal :open="deleteKeyModalOpen" @close="closeDeleteKeyModal">
  40. <div class="max-w-lg w-full bg-white rounded-lg shadow-2xl px-6 py-6">
  41. <h2
  42. class="font-semibold text-grey-900 text-2xl leading-tight border-b-2 border-grey-100 pb-4"
  43. >
  44. Remove U2F Device
  45. </h2>
  46. <p v-if="keys.length === 1" class="my-4 text-grey-700">
  47. Once this device is removed, <b>Two-Factor Authentication</b> will be disabled on your
  48. account.
  49. </p>
  50. <p v-else class="my-4 text-grey-700">
  51. Once this device is removed, <b>Two-Factor Authentication</b> will still be enabled as you
  52. have other U2F devices associated with your account.
  53. </p>
  54. <div class="mt-6">
  55. <button
  56. @click="remove"
  57. class="bg-red-500 hover:bg-red-600 text-white font-bold py-3 px-4 rounded focus:outline-none"
  58. :class="removeKeyLoading ? 'cursor-not-allowed' : ''"
  59. :disabled="removeKeyLoading"
  60. >
  61. Remove
  62. <loader v-if="removeKeyLoading" />
  63. </button>
  64. <button
  65. @click="closeDeleteKeyModal"
  66. class="ml-4 px-4 py-3 text-grey-800 font-semibold bg-white hover:bg-grey-50 border border-grey-100 rounded focus:outline-none"
  67. >
  68. Close
  69. </button>
  70. </div>
  71. </div>
  72. </Modal>
  73. </div>
  74. </template>
  75. <script>
  76. import Modal from './Modal.vue'
  77. export default {
  78. components: {
  79. Modal,
  80. },
  81. data() {
  82. return {
  83. deleteKeyModalOpen: false,
  84. keys: [],
  85. keyToRemove: null,
  86. loading: false,
  87. removeKeyLoading: false,
  88. }
  89. },
  90. mounted() {
  91. this.getWebauthnKeys()
  92. },
  93. methods: {
  94. getWebauthnKeys() {
  95. axios.get('/webauthn/keys').then(response => {
  96. this.keys = response.data
  97. })
  98. },
  99. showRemoveModal(token) {
  100. this.keyToRemove = token
  101. this.deleteKeyModalOpen = true
  102. },
  103. remove() {
  104. this.removeKeyLoading = true
  105. axios.delete(`/webauthn/${this.keyToRemove.id}`).then(response => {
  106. this.removeKeyLoading = false
  107. this.deleteKeyModalOpen = false
  108. this.keyToRemove = null
  109. if (this.keys.length === 1) {
  110. location.reload()
  111. } else {
  112. this.getWebauthnKeys()
  113. }
  114. })
  115. },
  116. closeDeleteKeyModal() {
  117. this.deleteKeyModalOpen = false
  118. },
  119. },
  120. }
  121. </script>