WebauthnKeys.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 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. <div class="mt-6">
  51. <button
  52. @click="remove"
  53. class="bg-red-500 hover:bg-red-600 text-white font-bold py-3 px-4 rounded focus:outline-none"
  54. :class="removeKeyLoading ? 'cursor-not-allowed' : ''"
  55. :disabled="removeKeyLoading"
  56. >
  57. Remove
  58. <loader v-if="removeKeyLoading" />
  59. </button>
  60. <button
  61. @click="closeDeleteKeyModal"
  62. 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"
  63. >
  64. Close
  65. </button>
  66. </div>
  67. </div>
  68. </Modal>
  69. </div>
  70. </template>
  71. <script>
  72. import Modal from './Modal.vue'
  73. export default {
  74. components: {
  75. Modal,
  76. },
  77. data() {
  78. return {
  79. deleteKeyModalOpen: false,
  80. keys: [],
  81. keyToRemove: null,
  82. loading: false,
  83. removeKeyLoading: false,
  84. }
  85. },
  86. mounted() {
  87. this.getWebauthnKeys()
  88. },
  89. methods: {
  90. getWebauthnKeys() {
  91. axios.get('/webauthn/keys').then(response => {
  92. this.keys = response.data
  93. })
  94. },
  95. showRemoveModal(token) {
  96. this.keyToRemove = token
  97. this.deleteKeyModalOpen = true
  98. },
  99. remove() {
  100. this.removeKeyLoading = true
  101. axios.delete(`/webauthn/${this.keyToRemove.id}`).then(response => {
  102. this.removeKeyLoading = false
  103. this.deleteKeyModalOpen = false
  104. this.keyToRemove = null
  105. if (this.keys.length === 1) {
  106. location.reload()
  107. } else {
  108. this.getWebauthnKeys()
  109. }
  110. })
  111. },
  112. closeDeleteKeyModal() {
  113. this.deleteKeyModalOpen = false
  114. },
  115. },
  116. }
  117. </script>