@sowell/quasar-app-extension-auth 0.5.1 → 1.0.0

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.
@@ -143,7 +143,7 @@
143
143
  persistent
144
144
  data-testid="ask-password-change-modal"
145
145
  >
146
- <web-send-email @resetPassword="resetPassword" />
146
+ <web-send-email @resetPassword="resetPassword" @close="() => forgottenPassword = false" />
147
147
  </q-dialog>
148
148
  <q-dialog v-model="isNotification" persistent>
149
149
  <sw-info-dialog
@@ -151,6 +151,7 @@
151
151
  :content="infoDialog.content"
152
152
  :image="infoDialog.image"
153
153
  :isOtp="isOtp"
154
+ @close="() => isNotification = false"
154
155
  >
155
156
  <q-btn
156
157
  :data-testid="infoDialog.canGoNext ? 'next-btn' : 'close-btn'"
@@ -171,27 +172,22 @@
171
172
  </template>
172
173
 
173
174
  <script lang="ts">
174
- import isEmail from "validator/es/lib/isEmail";
175
- import { defineComponent, ref, computed } from "vue";
176
- import { useAuthState } from "../../injects";
177
- import { useI18n } from "vue-i18n";
178
- import SwInfoDialog from "../dialogs/sw-info-dialog.vue";
179
- import WebSendEmail from "../dialogs/WebSendEmail.vue";
175
+ import { defineComponent, ref, computed } from "vue"
176
+ import { useI18n } from "vue-i18n"
177
+ import isEmail from "validator/es/lib/isEmail"
178
+ import { useAuthState } from "../../injects"
179
+ import SwInfoDialog from "../dialogs/sw-info-dialog.vue"
180
+ import WebSendEmail from "../dialogs/WebSendEmail.vue"
180
181
 
181
- import { useAuth } from "composables/auth";
182
- import MicrosoftLogo from "../../assets/logo-microsoft.svg";
182
+ import { useAuth } from "composables/auth"
183
+ import MicrosoftLogo from "../../assets/logo-microsoft.svg"
183
184
 
184
- interface HeadersInterface {
185
- headers: {
186
- "x-requested-roles"?: string;
187
- };
188
- }
189
185
  export default defineComponent({
190
186
  name: "Auth",
191
187
  components: { WebSendEmail, SwInfoDialog },
192
188
  setup() {
193
- const { t } = useI18n();
194
- const authState = useAuthState();
189
+ const { t } = useI18n()
190
+ const authState = useAuthState()
195
191
 
196
192
  const {
197
193
  email,
@@ -207,26 +203,26 @@ export default defineComponent({
207
203
  X_REQUESTED_ROLES,
208
204
  IS_OTP,
209
205
  APP_SERVER_BASE_URL,
206
+ icons,
207
+ USE_SSO,
210
208
  goToOtpValidation,
211
209
  onSubmit,
212
210
  retypeEmail,
213
211
  isSubmitBtnDisabled,
214
- icons,
215
- USE_SSO,
216
- msalAuth,
217
- } = useAuth();
212
+ msalAuth
213
+ } = useAuth()
218
214
 
219
215
  const IS_MANAGER = ["manager", "clean_manager", "admin"].includes(
220
216
  X_REQUESTED_ROLES
221
- );
222
- const isNotification = ref(false);
217
+ )
218
+ const isNotification = ref(false)
223
219
  const infoDialog = ref({
224
220
  title: "",
225
221
  content: "",
226
- image: "",
227
- });
222
+ image: ""
223
+ })
228
224
 
229
- const isOtp = computed(() => IS_OTP.toLowerCase() === "y");
225
+ const isOtp = computed(() => IS_OTP.toLowerCase() === "y")
230
226
  const submitBtnDisabled = computed(
231
227
  () =>
232
228
  !(
@@ -235,18 +231,18 @@ export default defineComponent({
235
231
  password.value &&
236
232
  password.value.length > 5
237
233
  )
238
- );
234
+ )
239
235
  const resetPassword = async (email: string) => {
240
236
  if (email) {
241
237
  const data = {
242
238
  auth: {
243
239
  email,
244
240
  base: APP_SERVER_BASE_URL,
245
- },
246
- };
241
+ }
242
+ }
247
243
  try {
248
244
  await authState.resetPassword(data).then(() => {
249
- localStorage.setItem("emailResetPassword", email);
245
+ localStorage.setItem("emailResetPassword", email)
250
246
  infoDialog.value = {
251
247
  canGoNext: true,
252
248
  title: t("auth.mailVerificationTitle"),
@@ -254,33 +250,35 @@ export default defineComponent({
254
250
  IS_OTP.toLowerCase() === "y"
255
251
  ? t("auth.otpValidationCode")
256
252
  : t("auth.mailVerificationSubtitle"),
257
- image: "emailVerification",
258
- };
259
- forgottenPassword.value = false;
260
- isNotification.value = true;
261
- });
253
+ image: "emailVerification"
254
+ }
255
+ forgottenPassword.value = false
256
+ isNotification.value = true
257
+ })
262
258
  } catch {
263
- isNotification.value = false;
259
+ isNotification.value = false
264
260
 
265
261
  infoDialog.value = {
266
262
  canGoNext: false,
267
263
  title: t("auth.userNotFoundTitle"),
268
264
  content: t("auth.userNotFoundSubtitle"),
269
- image: "userNotFound",
270
- };
265
+ image: "userNotFound"
266
+ }
271
267
 
272
- isNotification.value = true;
268
+ isNotification.value = true
273
269
  }
274
270
  }
275
- };
271
+ }
276
272
 
277
273
  const handleSubmit = () => {
278
- onSubmit("SoWell");
279
- };
274
+ onSubmit("SoWell")
275
+ }
280
276
 
281
277
  const handleInfoDialog = () => {
282
278
  if (infoDialog.value.canGoNext) {
283
279
  goToOtpValidation()
280
+ } else {
281
+ isNotification.value = false
284
282
  }
285
283
  }
286
284
 
@@ -299,20 +297,20 @@ export default defineComponent({
299
297
  IS_MANAGER,
300
298
  WELCOME_SUBTITLE,
301
299
  WELCOME_TITLE,
302
- isSubmitBtnDisabled,
303
- handleInfoDialog,
304
- retypeEmail,
305
- onSubmit,
306
300
  icons,
307
301
  USE_SSO,
308
302
  MicrosoftLogo,
309
- msalAuth,
310
303
  isOtp,
304
+ isSubmitBtnDisabled,
305
+ retypeEmail,
306
+ onSubmit,
307
+ msalAuth,
308
+ handleInfoDialog,
311
309
  resetPassword,
312
- handleSubmit,
313
- };
314
- },
315
- });
310
+ handleSubmit
311
+ }
312
+ }
313
+ })
316
314
  </script>
317
315
 
318
316
  <style scoped>
@@ -6,31 +6,26 @@
6
6
  <img
7
7
  src="../../assets/Sowell-logo.svg"
8
8
  class="q-mb-sm q-mr-md"
9
- style="width: 190px"
10
- />
9
+ style="width: 190px" />
11
10
  </div>
12
11
  <div
13
12
  class="column justify-center full-height"
14
- style="max-width: 550px; margin-top: -90px"
15
- >
13
+ style="max-width: 550px; margin-top: -90px">
16
14
  <div></div>
17
15
  <div
18
16
  class="text-subtitle1 q-mt-lg"
19
- style="font-size: 34px; font-weight: 600; line-height: 34px"
20
- >
17
+ style="font-size: 34px; font-weight: 600; line-height: 34px">
21
18
  {{ $t("auth.passwordRecovery") }}
22
19
  </div>
23
20
  <div
24
21
  class="text-subtitle1 q-mt-lg q-mb-lg"
25
- style="font-size: 16px; font-weight: 400; line-height: 24px"
26
- >
22
+ style="font-size: 16px; font-weight: 400; line-height: 24px">
27
23
  {{ $t("auth.recommendPassword") }}
28
24
  </div>
29
25
  <q-form
30
26
  class="column form"
31
27
  @submit="onSubmit"
32
- data-testid="reset-password-form"
33
- >
28
+ data-testid="reset-password-form">
34
29
  <div>
35
30
  <div class="q-mb-sm" style="font-size: 14px; font-weight: 600">
36
31
  {{ $t("auth.newPassword") }}
@@ -45,18 +40,15 @@
45
40
  :type="showPassword ? 'text' : 'password'"
46
41
  bg-color="white"
47
42
  dense
48
- class="full-width q-mb-md"
49
- >
43
+ class="full-width q-mb-md">
50
44
  <template #append>
51
45
  <q-icon
52
- :name="
53
- showPassword
54
- ? icons.ionEyeOffOutline
55
- : icons.ionEyeOutline
56
- "
46
+ :name="showPassword
47
+ ? icons.ionEyeOffOutline
48
+ : icons.ionEyeOutline
49
+ "
57
50
  class="cursor-pointer q-mr-sm"
58
- @click="showPassword = !showPassword"
59
- />
51
+ @click="showPassword = !showPassword" />
60
52
  </template>
61
53
  </q-input>
62
54
  </div>
@@ -71,8 +63,7 @@
71
63
  no-caps
72
64
  class="submitBtn"
73
65
  data-cy="send-new-password"
74
- :disable="!canSubmit"
75
- />
66
+ :disable="!canSubmit" />
76
67
  </div>
77
68
  </q-form>
78
69
  </div>
@@ -83,18 +74,16 @@
83
74
  :content="$t('auth.passwordUpdated')"
84
75
  :image="'passwordUpdated'"
85
76
  :passwordUpdated="passwordUpdated"
86
- @goToLoginPage="goToLoginPage"
87
- />
77
+ @goToLoginPage="goToLoginPage" />
88
78
  </q-dialog>
89
79
  </div>
90
80
  </q-layout>
91
81
  </template>
92
82
 
93
83
  <script lang="ts">
94
- //@ts-ignore
95
- import { defineComponent } from "vue";
96
- import SwInfoDialog from "../dialogs/sw-info-dialog.vue";
97
- import { useResetPassword } from "composables/resetPassword";
84
+ import { defineComponent } from "vue"
85
+ import SwInfoDialog from "../dialogs/sw-info-dialog.vue"
86
+ import { useResetPassword } from "composables/resetPassword"
98
87
 
99
88
  export default defineComponent({
100
89
  name: "ResetPassword",
@@ -107,10 +96,10 @@ export default defineComponent({
107
96
  showPassword,
108
97
  validations,
109
98
  canSubmit,
110
- onSubmit,
111
- goToLoginPage,
112
99
  icons,
113
- } = useResetPassword();
100
+ onSubmit,
101
+ goToLoginPage
102
+ } = useResetPassword()
114
103
 
115
104
  return {
116
105
  password,
@@ -119,12 +108,12 @@ export default defineComponent({
119
108
  canSubmit,
120
109
  passwordUpdated,
121
110
  showPassword,
111
+ icons,
122
112
  goToLoginPage,
123
- onSubmit,
124
- icons,
125
- };
126
- },
127
- });
113
+ onSubmit
114
+ }
115
+ }
116
+ })
128
117
  </script>
129
118
 
130
119
  <style scoped>
@@ -132,4 +121,3 @@ export default defineComponent({
132
121
  width: 254px;
133
122
  }
134
123
  </style>
135
-
@@ -1,6 +1,6 @@
1
- import { ref, onMounted, inject } from "vue";
2
- import isEmail from "validator/es/lib/isEmail";
3
- import { useI18n } from "vue-i18n";
1
+ import { ref, onMounted, inject } from "vue"
2
+ import isEmail from "validator/es/lib/isEmail"
3
+ import { useI18n } from "vue-i18n"
4
4
  import {
5
5
  ionMailOutline,
6
6
  ionLockClosedOutline,
@@ -8,8 +8,8 @@ import {
8
8
  ionEyeOffOutline,
9
9
  ionEyeSharp,
10
10
  ionEyeOffSharp,
11
- } from "@quasar/extras/ionicons-v5";
12
- import { Platform } from "quasar";
11
+ } from "@quasar/extras/ionicons-v5"
12
+ import { Platform } from "quasar"
13
13
 
14
14
  import {
15
15
  $prompts,
@@ -17,26 +17,26 @@ import {
17
17
  SignInPayload,
18
18
  useAuthState,
19
19
  useMsalState,
20
- } from "../injects";
20
+ } from "../injects"
21
21
 
22
22
  interface HeadersInterface {
23
23
  headers: {
24
- "x-requested-roles"?: string;
25
- };
24
+ "x-requested-roles"?: string
25
+ }
26
26
  }
27
27
 
28
28
  export function useAuth() {
29
- const authState = useAuthState();
30
- const msalState = useMsalState();
31
- const device = inject("Device");
29
+ const authState = useAuthState()
30
+ const msalState = useMsalState()
31
+ const device = inject("Device")
32
32
  let deviceInfos = {
33
33
  manufacturer: "",
34
34
  model: "",
35
35
  platform: "",
36
- version: "",
37
- };
36
+ version: ""
37
+ }
38
38
 
39
- const { t } = useI18n();
39
+ const { t } = useI18n()
40
40
  const {
41
41
  LOCAL_SUCCESS_REDIRECTION_ROUTE,
42
42
  APP_SERVER_BASE_URL,
@@ -46,112 +46,115 @@ export function useAuth() {
46
46
  IS_OTP,
47
47
  LOCAL_OTP_ROUTE,
48
48
  APP_VERSION,
49
- USE_SSO,
50
- } = $prompts();
51
- const { push, replace } = $router();
49
+ USE_SSO
50
+ } = $prompts()
51
+ const { push, replace } = $router()
52
52
 
53
- const email = ref("");
54
- const password = ref("");
55
- const msalToken = ref("");
56
- const loading = ref(false);
57
- const msalLoading = ref(false);
58
- const showPassword = ref(false);
59
- const forgottenPassword = ref(false);
60
- const isReset = ref(false);
61
- const sendEmailSuccess = ref(false);
62
- const emailResetPassword = ref("");
63
- const errorEmailMessage = ref("");
64
- const errorPasswordMessage = ref("");
53
+ const email = ref("")
54
+ const password = ref("")
55
+ const msalToken = ref("")
56
+ const loading = ref(false)
57
+ const msalLoading = ref(false)
58
+ const showPassword = ref(false)
59
+ const forgottenPassword = ref(false)
60
+ const isReset = ref(false)
61
+ const sendEmailSuccess = ref(false)
62
+ const emailResetPassword = ref("")
63
+ const errorEmailMessage = ref("")
64
+ const errorPasswordMessage = ref("")
65
65
  const validations = ref({
66
66
  email: [
67
67
  (val: string) => {
68
- errorEmailMessage.value = !!val ? "" : t("auth.emailPresenceError");
69
- return !!val || t("auth.emailPresenceError");
68
+ errorEmailMessage.value = !!val ? "" : t("auth.emailPresenceError")
69
+ return !!val || t("auth.emailPresenceError")
70
70
  },
71
71
  (val: string) => {
72
72
  errorEmailMessage.value = isEmail(val.trim())
73
73
  ? ""
74
- : t("auth.emailValidationError");
75
- return isEmail(val.trim()) || t("auth.emailValidationError");
76
- },
74
+ : t("auth.emailValidationError")
75
+ return isEmail(val.trim()) || t("auth.emailValidationError")
76
+ }
77
77
  ],
78
78
  password: [
79
79
  (val: string) => {
80
80
  errorPasswordMessage.value = !!val
81
81
  ? ""
82
- : t("auth.passwordPresenceError");
83
- return !!val || t("auth.passwordPresenceError");
84
- },
85
- ],
86
- });
82
+ : t("auth.passwordPresenceError")
83
+ return !!val || t("auth.passwordPresenceError")
84
+ }
85
+ ]
86
+ })
87
87
 
88
88
  const retypeEmail = () => {
89
- forgottenPassword.value = true;
90
- };
89
+ forgottenPassword.value = true
90
+ }
91
91
 
92
92
  const deviceInfo = async () => {
93
93
  if (device) {
94
- const info = await device.getInfo();
94
+ const info = await device.getInfo()
95
95
  deviceInfos = {
96
96
  manufacturer: info.manufacturer,
97
97
  model: info.model,
98
98
  platform: info.platform,
99
- version: info.osVersion,
100
- };
99
+ version: info.osVersion
100
+ }
101
101
  }
102
- };
102
+ }
103
103
 
104
104
  const onSubmit = async (provider = "SoWell") => {
105
105
  if (provider === "SoWell") {
106
- loading.value = true;
106
+ loading.value = true
107
107
  }
108
108
  const data: SignInPayload = {
109
109
  auth: {
110
110
  email: email.value,
111
111
  password: provider === "SoWell" ? password.value : undefined,
112
- msalToken: provider === "MSAL" ? msalToken.value : undefined,
113
- },
114
- };
112
+ msalToken: provider === "MSAL" ? msalToken.value : undefined
113
+ }
114
+ }
115
115
  if (device && Platform.is.capacitor) {
116
116
  (data["device-clean"] = {
117
117
  manufacturer: deviceInfos.manufacturer,
118
118
  model: deviceInfos.model,
119
119
  platform: deviceInfos.platform,
120
- version: deviceInfos.version,
120
+ version: deviceInfos.version
121
121
  }),
122
122
  (data["app-clean"] = {
123
- versionNumber: APP_VERSION,
124
- });
123
+ versionNumber: APP_VERSION
124
+ })
125
125
  }
126
126
  const options: HeadersInterface = {
127
- headers: {},
128
- };
127
+ headers: {}
128
+ }
129
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
129
130
  // @ts-ignore
130
- let requestedRoles = window.Cypress
131
+ const requestedRoles = window.Cypress
132
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
131
133
  ? // @ts-ignore
132
134
  window.Cypress.requestedRoles
133
- : X_REQUESTED_ROLES;
134
- if (requestedRoles) options.headers["x-requested-roles"] = requestedRoles;
135
+ : X_REQUESTED_ROLES
136
+ if (requestedRoles) options.headers["x-requested-roles"] = requestedRoles
135
137
 
136
138
  try {
137
- await authState.signin(data, options);
138
- loading.value = false;
139
- msalLoading.value = false;
139
+ await authState.signin(data, options)
140
+ loading.value = false
141
+ msalLoading.value = false
142
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
140
143
  // @ts-ignore
141
144
  if (!window.Cypress) {
142
145
  // FIXME: encrypt password
143
146
  localStorage.setItem(
144
147
  "credentials",
145
148
  JSON.stringify({ ...data.auth, provider: provider })
146
- );
149
+ )
147
150
  }
148
- push(LOCAL_SUCCESS_REDIRECTION_ROUTE);
151
+ push(LOCAL_SUCCESS_REDIRECTION_ROUTE)
149
152
  } catch (err) {
150
- console.error("onSubmit", err);
151
- loading.value = false;
152
- msalLoading.value = false;
153
+ console.error("onSubmit", err)
154
+ loading.value = false
155
+ msalLoading.value = false
153
156
  }
154
- };
157
+ }
155
158
 
156
159
  const isSubmitBtnDisabled = () => {
157
160
  return !(
@@ -159,47 +162,49 @@ export function useAuth() {
159
162
  isEmail(email.value) &&
160
163
  password.value &&
161
164
  password.value.length > 5
162
- );
163
- };
165
+ )
166
+ }
164
167
 
165
168
  const deviceReady = () => {
166
169
  if (localStorage.getItem("credentials")) {
170
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
167
171
  // @ts-ignore
168
- email.value = JSON.parse(localStorage.getItem("credentials")).email;
172
+ email.value = JSON.parse(localStorage.getItem("credentials")).email
173
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
169
174
  // @ts-ignore
170
- password.value = JSON.parse(localStorage.getItem("credentials")).password;
175
+ password.value = JSON.parse(localStorage.getItem("credentials")).password
171
176
  }
172
- };
177
+ }
173
178
 
174
179
  const goToOtpValidation = () => {
175
- push(LOCAL_OTP_ROUTE);
176
- };
180
+ push(LOCAL_OTP_ROUTE)
181
+ }
177
182
 
178
183
  const msalAuth = () => {
179
- msalLoading.value = true;
184
+ msalLoading.value = true
180
185
  msalState.signIn().then(
181
- async (result) => {
182
- email.value = result.email;
183
- msalToken.value = result.token;
184
- await onSubmit("MSAL");
185
- msalLoading.value = false;
186
+ async (result: { email: string; token: string }) => {
187
+ email.value = result.email
188
+ msalToken.value = result.token
189
+ await onSubmit("MSAL")
190
+ msalLoading.value = false
186
191
  },
187
192
  () => {
188
- msalLoading.value = false;
189
- msalState.reset();
193
+ msalLoading.value = false
194
+ msalState.reset()
190
195
  }
191
- );
192
- };
196
+ )
197
+ }
193
198
 
194
199
  onMounted(async () => {
195
- await deviceInfo();
200
+ await deviceInfo()
196
201
  if (authState.raw) {
197
- replace(LOCAL_SUCCESS_REDIRECTION_ROUTE);
202
+ replace(LOCAL_SUCCESS_REDIRECTION_ROUTE)
198
203
  }
199
204
  if (Platform.is.capacitor) {
200
- deviceReady();
205
+ deviceReady()
201
206
  }
202
- });
207
+ })
203
208
 
204
209
  return {
205
210
  email,
@@ -235,6 +240,6 @@ export function useAuth() {
235
240
  ionEyeOffOutline,
236
241
  ionEyeSharp,
237
242
  ionEyeOffSharp,
238
- },
239
- };
243
+ }
244
+ }
240
245
  }