@sowell/quasar-app-extension-auth 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sowell/quasar-app-extension-auth",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "A Quasar app extension to manage Authentication",
5
5
  "main": "src/index.js",
6
6
  "repository": "https://github.com/sowell-ai/quasar.extension.auth",
@@ -148,10 +148,10 @@
148
148
  :title="infoDialog.title"
149
149
  :content="infoDialog.content"
150
150
  :image="infoDialog.image"
151
- :isOtp="true"
151
+ :isOtp="isOtp"
152
152
  >
153
153
  <q-btn
154
- v-if="requestedOtp"
154
+ v-if="isOtp"
155
155
  class="bg-white submitBtn"
156
156
  unelevated
157
157
  outline
@@ -217,13 +217,13 @@ export default defineComponent({
217
217
  X_REQUESTED_ROLES
218
218
  );
219
219
  const isNotification = ref(false);
220
- const requestedOtp = ref(false);
221
220
  const infoDialog = ref({
222
221
  title: "",
223
222
  content: "",
224
223
  image: "",
225
224
  });
226
225
 
226
+ const isOtp = computed(() => IS_OTP.toLowerCase() === "y");
227
227
  const submitBtnDisabled = computed(
228
228
  () =>
229
229
  !(
@@ -254,16 +254,15 @@ export default defineComponent({
254
254
  };
255
255
  forgottenPassword.value = false;
256
256
  isNotification.value = true;
257
- requestedOtp.value = true;
258
257
  });
259
258
  } catch {
260
- requestedOtp.value = false;
259
+ isNotification.value = false;
260
+
261
261
  infoDialog.value = {
262
262
  title: t("auth.userNotFoundTitle"),
263
263
  content: t("auth.userNotFoundSubtitle"),
264
264
  image: "userNotFound",
265
265
  };
266
- isNotification.value = true;
267
266
  }
268
267
  }
269
268
  };
@@ -288,7 +287,6 @@ export default defineComponent({
288
287
  WELCOME_SUBTITLE,
289
288
  WELCOME_TITLE,
290
289
  isSubmitBtnDisabled,
291
- requestedOtp,
292
290
  goToOtpValidation,
293
291
  retypeEmail,
294
292
  onSubmit,
@@ -296,6 +294,7 @@ export default defineComponent({
296
294
  USE_SSO,
297
295
  MicrosoftLogo,
298
296
  msalAuth,
297
+ isOtp,
299
298
  resetPassword,
300
299
  handleSubmit,
301
300
  };
@@ -26,7 +26,7 @@ export function useResetPassword() {
26
26
  const loading = ref(false);
27
27
  const passwordUpdated = ref(false);
28
28
  const showPassword = ref(false);
29
- const token = ref("");
29
+ const tempToken = ref("");
30
30
  const userInfos = JSON.parse(localStorage.getItem("userInfos") || "{}");
31
31
 
32
32
  const { patch, post } = $api();
@@ -40,11 +40,12 @@ export function useResetPassword() {
40
40
  const $route = router.currentRoute.value;
41
41
 
42
42
  const decodedToken = computed(() => {
43
- if (!token.value) return null;
44
- return jwt(token.value) as DecodedToken;
43
+ if (!tempToken.value) return null;
44
+ return jwt(tempToken.value) as DecodedToken;
45
45
  }) as Ref<DecodedToken | null>;
46
46
 
47
47
  const isOtp = computed(() => IS_OTP.toLowerCase() === "y");
48
+
48
49
  const canSubmit = computed(() => {
49
50
  return (
50
51
  (decodedToken.value !== null || userInfos?.uid) &&
@@ -93,8 +94,10 @@ export function useResetPassword() {
93
94
  };
94
95
 
95
96
  const onSubmit = () => {
96
- let idUser =
97
- isOtp && userInfos?.uid ? userInfos?.uid : decodedToken?.value?.sub;
97
+ let idUser = decodedToken?.value?.sub;
98
+ if (isOtp.value && userInfos?.uid) {
99
+ idUser = userInfos?.uid;
100
+ }
98
101
  const updatePasswordPayload = {
99
102
  data: {
100
103
  type: "users",
@@ -104,9 +107,15 @@ export function useResetPassword() {
104
107
  },
105
108
  },
106
109
  };
110
+
111
+ let authorization = `Bearer ${tempToken.value}`;
112
+ if (isOtp.value) {
113
+ authorization = `Bearer ${userInfos?.token}`;
114
+ }
115
+
107
116
  const updatePasswordHeaders = {
108
117
  headers: {
109
- Authorization: `Bearer ${isOtp ? userInfos?.token : token.value}`,
118
+ Authorization: authorization,
110
119
  },
111
120
  };
112
121
  loading.value = true;
@@ -144,7 +153,7 @@ export function useResetPassword() {
144
153
  };
145
154
 
146
155
  onMounted(() => {
147
- if (IS_OTP.toLowerCase() === "n") {
156
+ if (!isOtp.value) {
148
157
  let key = $route.query.key as string;
149
158
  const { decoded, email, tmpToken } = decodeKey(key);
150
159
 
@@ -172,8 +181,8 @@ export function useResetPassword() {
172
181
 
173
182
  post(AUTH_SERVER_SIGNING_ROUTE, tmpAuthPayload)
174
183
  .then((response) => {
175
- token.value = response.data.jwt;
176
- if (!token.value) throw "Error reading the temporary token";
184
+ tempToken.value = response.data.jwt;
185
+ if (!tempToken.value) throw "Error reading the temporary token";
177
186
  })
178
187
  .catch((error) => {
179
188
  if (error.response) {