WebauthnKeys.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div>
  3. <div class="mt-6">
  4. <h3 class="font-bold text-xl">Device Authentication (U2F)</h3>
  5. <div class="my-4 w-24 border-b-2 border-grey-200"></div>
  6. <p class="my-6">
  7. Webauthn Keys you have registered for 2nd factor authentication. To remove a key simply
  8. click the delete button next to it. Disabling all keys will turn off 2FA on your account.
  9. </p>
  10. <div>
  11. <p class="mb-0" v-if="keys.length === 0">You have not registered any Webauthn Keys.</p>
  12. <div class="table w-full text-sm md:text-base" v-if="keys.length > 0">
  13. <div class="table-row">
  14. <div class="table-cell p-1 md:p-4 font-semibold">Name</div>
  15. <div class="table-cell p-1 md:p-4 font-semibold">Created</div>
  16. <div class="table-cell p-1 md:p-4 font-semibold">Enabled</div>
  17. <div class="table-cell p-1 md:p-4 text-right">
  18. <a href="/webauthn/register" class="text-indigo-700">Add New Device</a>
  19. </div>
  20. </div>
  21. <div v-for="key in keys" :key="key.id" class="table-row even:bg-grey-50 odd:bg-white">
  22. <div class="table-cell p-1 md:p-4">{{ key.name }}</div>
  23. <div class="table-cell p-1 md:p-4">{{ key.created_at | timeAgo }}</div>
  24. <div class="table-cell p-1 md:p-4">
  25. <Toggle v-model="key.enabled" @on="enableKey(key.id)" @off="disableKey(key.id)" />
  26. </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. import Toggle from './../components/Toggle.vue'
  78. export default {
  79. components: {
  80. Modal,
  81. Toggle,
  82. },
  83. data() {
  84. return {
  85. deleteKeyModalOpen: false,
  86. keys: [],
  87. keyToRemove: null,
  88. loading: false,
  89. removeKeyLoading: false,
  90. }
  91. },
  92. mounted() {
  93. this.getWebauthnKeys()
  94. },
  95. methods: {
  96. getWebauthnKeys() {
  97. axios.get('/webauthn/keys').then(response => {
  98. this.keys = response.data
  99. })
  100. },
  101. showRemoveModal(token) {
  102. this.keyToRemove = token
  103. this.deleteKeyModalOpen = true
  104. },
  105. remove() {
  106. this.removeKeyLoading = true
  107. axios.delete(`/webauthn/${this.keyToRemove.id}`).then(response => {
  108. this.removeKeyLoading = false
  109. this.deleteKeyModalOpen = false
  110. this.keyToRemove = null
  111. if (this.keys.length === 1) {
  112. location.reload()
  113. } else {
  114. this.getWebauthnKeys()
  115. }
  116. })
  117. },
  118. enableKey(id) {
  119. axios
  120. .post(
  121. `/webauthn/enabled-keys`,
  122. JSON.stringify({
  123. id: id,
  124. }),
  125. {
  126. headers: { 'Content-Type': 'application/json' },
  127. }
  128. )
  129. .then(response => {
  130. //
  131. })
  132. .catch(error => {
  133. if (error.response !== undefined) {
  134. this.error(error.response.data)
  135. } else {
  136. this.error()
  137. }
  138. })
  139. },
  140. disableKey(id) {
  141. axios
  142. .delete(`/webauthn/enabled-keys/${id}`)
  143. .then(response => {
  144. //
  145. })
  146. .catch(error => {
  147. if (error.response !== undefined) {
  148. this.error(error.response.data)
  149. } else {
  150. this.error()
  151. }
  152. })
  153. },
  154. closeDeleteKeyModal() {
  155. this.deleteKeyModalOpen = false
  156. },
  157. },
  158. }
  159. </script>