44 <div class =" space-y-6 bg-white py-6 px-4 sm:p-6" >
55 <div >
66 <h3 class =" text-lg font-medium leading-6 text-gray-900" >{{ title }}</h3 >
7- <p v-if =" !auth .profile.password" class =" mt-1 text-sm text-gray-500" >
7+ <p v-if =" !authStore .profile.password" class =" mt-1 text-sm text-gray-500" >
88 Secure your account by adding a password, or enabling two-factor security. Or both. Any changes will
99 require you to enter your original password.
1010 </p >
144144import { Switch , Dialog , DialogPanel , DialogTitle , TransitionChild , TransitionRoot } from " @headlessui/vue"
145145import { QrCodeIcon } from " @heroicons/vue/24/outline"
146146import QrcodeVue from " qrcode.vue"
147- import { useAuthStore } from " @/stores"
147+ import { useAuthStore , useTokenStore } from " @/stores"
148148import { apiAuth } from " @/api"
149149import { IUserProfileUpdate , INewTOTP , IEnableTOTP } from " @/interfaces"
150150
151151
152- const auth = useAuthStore ()
152+ const authStore = useAuthStore ()
153+ const tokenStore = useTokenStore ()
153154let profile = {} as IUserProfileUpdate
154155const title = " Security"
155156const redirectTOTP = " /settings"
@@ -160,7 +161,7 @@ const totpClaim = ref({} as IEnableTOTP)
160161const qrSize = 200
161162
162163const schema = {
163- original: { required: auth .profile .password , min: 8 , max: 64 },
164+ original: { required: authStore .profile .password , min: 8 , max: 64 },
164165 password: { required: false , min: 8 , max: 64 },
165166 confirmation: { required: false , confirmed: " password" }
166167}
@@ -171,7 +172,7 @@ const totpSchema = {
171172
172173onMounted ( () => {
173174 resetProfile ()
174- totpEnabled .value = auth .profile .totp
175+ totpEnabled .value = authStore .profile .totp
175176})
176177
177178function resetProfile() {
@@ -183,24 +184,24 @@ function resetProfile() {
183184// @ts-ignore
184185async function enableTOTP(values : any , { resetForm }) {
185186 totpClaim .value .claim = values .claim
186- await auth .enableTOTPAuthentication (totpClaim .value )
187+ await authStore .enableTOTPAuthentication (totpClaim .value )
187188 resetForm ()
188189 totpModal .value = false
189190}
190191
191192// @ts-ignore
192193async function submit(values : any , { resetForm }) {
193194 profile = {}
194- if ((! auth .profile .password && ! values .original ) ||
195- (auth .profile .password && values .original )) {
195+ if ((! authStore .profile .password && ! values .original ) ||
196+ (authStore .profile .password && values .original )) {
196197 if (values .original ) profile .original = values .original
197198 if (values .password && values .password !== values .original ) {
198199 profile .password = values .password
199- await auth .updateUserProfile (profile )
200+ await authStore .updateUserProfile (profile )
200201 }
201- if (totpEnabled .value !== auth .profile .totp && totpEnabled .value ) {
202- await auth . authTokens .refreshTokens ()
203- const { data : response } = await apiAuth .requestNewTOTP (auth . authTokens .token )
202+ if (totpEnabled .value !== authStore .profile .totp && totpEnabled .value ) {
203+ await tokenStore .refreshTokens ()
204+ const { data : response } = await apiAuth .requestNewTOTP (tokenStore .token )
204205 if (response .value ) {
205206 totpNew .value .key = response .value .key
206207 totpNew .value .uri = response .value .uri
@@ -209,8 +210,8 @@ async function submit(values: any, { resetForm }) {
209210 totpModal .value = true
210211 }
211212 }
212- if (totpEnabled .value !== auth .profile .totp && ! totpEnabled .value ) {
213- await auth .disableTOTPAuthentication (profile )
213+ if (totpEnabled .value !== authStore .profile .totp && ! totpEnabled .value ) {
214+ await authStore .disableTOTPAuthentication (profile )
214215 }
215216 resetForm ()
216217 }
0 commit comments