@sowell/quasar-app-extension-auth 1.0.0 → 1.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sowell/quasar-app-extension-auth",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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",
@@ -42,6 +42,7 @@
42
42
  "@quasar/extras": "^1.15.2",
43
43
  "axios": "^0.21.1",
44
44
  "buffer": "^6.0.3",
45
+ "crypto-js": "^4.2.0",
45
46
  "pinia": "^2.0.12",
46
47
  "qs": "^6.10.1",
47
48
  "validator": "^13.6.0",
@@ -212,7 +212,7 @@ export default defineComponent({
212
212
  msalAuth
213
213
  } = useAuth()
214
214
 
215
- const IS_MANAGER = ["manager", "clean_manager", "admin"].includes(
215
+ const IS_MANAGER = ["manager", "clean_manager", "incivility_manager", "admin"].includes(
216
216
  X_REQUESTED_ROLES
217
217
  )
218
218
  const isNotification = ref(false)
@@ -9,7 +9,9 @@ import {
9
9
  ionEyeSharp,
10
10
  ionEyeOffSharp,
11
11
  } from "@quasar/extras/ionicons-v5"
12
- import { Platform } from "quasar"
12
+ import { Platform, useQuasar } from "quasar"
13
+
14
+ import { encrypt, decrypt } from "../utils/encryption"
13
15
 
14
16
  import {
15
17
  $prompts,
@@ -37,6 +39,7 @@ export function useAuth() {
37
39
  }
38
40
 
39
41
  const { t } = useI18n()
42
+ const { localStorage } = useQuasar()
40
43
  const {
41
44
  LOCAL_SUCCESS_REDIRECTION_ROUTE,
42
45
  APP_SERVER_BASE_URL,
@@ -142,11 +145,9 @@ export function useAuth() {
142
145
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
143
146
  // @ts-ignore
144
147
  if (!window.Cypress) {
145
- // FIXME: encrypt password
146
- localStorage.setItem(
147
- "credentials",
148
- JSON.stringify({ ...data.auth, provider: provider })
149
- )
148
+
149
+ data.auth.password = encrypt(password.value);
150
+ localStorage.set("credentials",{ ...data.auth, provider: provider })
150
151
  }
151
152
  push(LOCAL_SUCCESS_REDIRECTION_ROUTE)
152
153
  } catch (err) {
@@ -166,13 +167,20 @@ export function useAuth() {
166
167
  }
167
168
 
168
169
  const deviceReady = () => {
169
- if (localStorage.getItem("credentials")) {
170
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
171
- // @ts-ignore
172
- email.value = JSON.parse(localStorage.getItem("credentials")).email
173
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
174
- // @ts-ignore
175
- password.value = JSON.parse(localStorage.getItem("credentials")).password
170
+ if (localStorage.has("credentials")) {
171
+ const credentials = localStorage.getItem("credentials")
172
+ email.value = credentials.email
173
+ password.value = credentials.password
174
+ }
175
+ }
176
+
177
+ const tryAutoLogin = async () => {
178
+ if (localStorage.has("credentials")) {
179
+ const credentials = localStorage.getItem("credentials")
180
+ const decryptedPassword = decrypt(credentials.password);
181
+ email.value = credentials.email
182
+ password.value = decryptedPassword
183
+ await onSubmit()
176
184
  }
177
185
  }
178
186
 
@@ -204,6 +212,7 @@ export function useAuth() {
204
212
  if (Platform.is.capacitor) {
205
213
  deviceReady()
206
214
  }
215
+ tryAutoLogin()
207
216
  })
208
217
 
209
218
  return {
@@ -16,7 +16,7 @@ const {
16
16
  } = prompts
17
17
 
18
18
  // FIXME: Utiliser le UI_PAGE pour choisir les page a utiliser pour la version web ou mobile (auth et reset password)
19
- const webAuthRoles = ["superadmin", "clean_manager", "manager"]
19
+ const webAuthRoles = ["superadmin", "clean_manager", "incivility_manager", "manager"]
20
20
  const AdminAuthRoles = ["admin"]
21
21
 
22
22
  let authPage = ""
@@ -0,0 +1,9 @@
1
+ import CryptoJS from "crypto-js";
2
+
3
+ export function encrypt(password: string): string {
4
+ return CryptoJS.AES.encrypt(password, process.env.ENCRYPTION_KEY).toString()
5
+ }
6
+
7
+ export function decrypt(encryptedPassword: string): string {
8
+ return CryptoJS.AES.decrypt(encryptedPassword, process.env.ENCRYPTION_KEY).toString(CryptoJS.enc.Utf8)
9
+ }
@@ -0,0 +1 @@
1
+ export { encrypt, decrypt } from "./encryption"