@sowell/quasar-app-extension-auth 0.5.2 → 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.
@@ -1,124 +1,124 @@
1
- import { useQuasar } from "quasar";
2
- import { useI18n } from "vue-i18n";
3
- import jwt from "jwt-decode";
4
- import { computed, ref, Ref, onMounted } from "vue";
1
+ import { useQuasar } from "quasar"
2
+ import { useI18n } from "vue-i18n"
3
+ import jwt from "jwt-decode"
4
+ import { computed, ref, Ref, onMounted } from "vue"
5
5
  import {
6
6
  ionCloseOutline,
7
7
  ionEyeOutline,
8
8
  ionEyeOffOutline,
9
9
  ionAlertCircleOutline,
10
10
  ionLockClosedOutline,
11
- } from "@quasar/extras/ionicons-v5";
11
+ } from "@quasar/extras/ionicons-v5"
12
12
 
13
- import { $api, $prompts, $router } from "../injects";
14
- import { Buffer } from "buffer/"; // NOTE: the trailing '/' is intentional and required by buffer
13
+ import { $api, $prompts, $router } from "../injects"
14
+ import { Buffer } from "buffer/" // NOTE: the trailing '/' is intentional and required by buffer
15
15
 
16
16
  interface DecodedToken {
17
- sub: number;
18
- email: string;
19
- token: string;
17
+ sub: number
18
+ email: string
19
+ token: string
20
20
  }
21
21
  export function useResetPassword() {
22
- const $q = useQuasar();
23
- const { t } = useI18n();
24
-
25
- const password = ref("");
26
- const loading = ref(false);
27
- const passwordUpdated = ref(false);
28
- const showPassword = ref(false);
29
- const tempToken = ref("");
30
- const userInfos = JSON.parse(localStorage.getItem("userInfos") || "{}");
31
-
32
- const { patch, post } = $api();
33
- const router = $router();
22
+ const $q = useQuasar()
23
+ const { t } = useI18n()
24
+
25
+ const password = ref("")
26
+ const loading = ref(false)
27
+ const passwordUpdated = ref(false)
28
+ const showPassword = ref(false)
29
+ const tempToken = ref("")
30
+ const userInfos = JSON.parse(localStorage.getItem("userInfos") || "{}")
31
+
32
+ const { patch, post } = $api()
33
+ const router = $router()
34
34
  const {
35
35
  AUTH_SERVER_SIGNING_ROUTE,
36
36
  AUTH_SERVER_UPDATE_PASSWORD_ROUTE,
37
37
  LOCAL_LOGIN_ROUTE,
38
- IS_OTP,
39
- } = $prompts();
40
- const $route = router.currentRoute.value;
38
+ IS_OTP
39
+ } = $prompts()
40
+ const $route = router.currentRoute.value
41
41
 
42
42
  const decodedToken = computed(() => {
43
- if (!tempToken.value) return null;
44
- return jwt(tempToken.value) as DecodedToken;
45
- }) as Ref<DecodedToken | null>;
43
+ if (!tempToken.value) return null
44
+ return jwt(tempToken.value) as DecodedToken
45
+ }) as Ref<DecodedToken | null>
46
46
 
47
- const isOtp = computed(() => IS_OTP.toLowerCase() === "y");
47
+ const isOtp = computed(() => IS_OTP.toLowerCase() === "y")
48
48
 
49
49
  const canSubmit = computed(() => {
50
50
  return (
51
51
  (decodedToken.value !== null || userInfos?.uid) &&
52
52
  password.value.length >= 6
53
- );
54
- });
53
+ )
54
+ })
55
55
 
56
56
  const validations = {
57
57
  passwordRules: [
58
58
  (val: string) => !!val || t("auth.passwordPresenceError"),
59
- (val: string) => val.length >= 6 || t("auth.passwordLengthError"),
59
+ (val: string) => val.length >= 6 || t("auth.passwordLengthError")
60
60
  ],
61
61
  passwordConfirmationRules: [
62
62
  (val: string) =>
63
63
  val === password.value || t("auth.newPasswordConfirmationFailed"),
64
64
  (val: string) => !!val || t("auth.passwordPresenceError"),
65
- (val: string) => val.length >= 6 || t("auth.passwordLengthError"),
66
- ],
67
- };
65
+ (val: string) => val.length >= 6 || t("auth.passwordLengthError")
66
+ ]
67
+ }
68
68
 
69
69
  const decodeKey = (key: string) => {
70
70
  try {
71
71
  // remove backslash to avoid decoding error
72
- key = key.replace(/\\n/g, "");
72
+ key = key.replace(/\\n/g, "")
73
73
  const decodedKey = Buffer.from(key, "base64")
74
74
  .toString("utf-8")
75
- .split(",");
75
+ .split(",")
76
76
  // split instead of JSON.parse as JSON.parse doesn't work
77
77
 
78
78
  if (decodedKey.length !== 2) {
79
- throw "Invalid encoded key";
79
+ throw "Invalid encoded key"
80
80
  }
81
81
 
82
- const email = decodedKey[0].replace("{", "").split(":")[1];
83
- const tmpToken = decodedKey[1].replace("}", "").split(":")[1];
82
+ const email = decodedKey[0].replace("{", "").split(":")[1]
83
+ const tmpToken = decodedKey[1].replace("}", "").split(":")[1]
84
84
  return {
85
85
  decoded: true,
86
86
  email,
87
- tmpToken,
88
- };
87
+ tmpToken
88
+ }
89
89
  } catch (err) {
90
90
  return {
91
- decoded: false,
92
- };
91
+ decoded: false
92
+ }
93
93
  }
94
- };
94
+ }
95
95
 
96
96
  const onSubmit = () => {
97
- let idUser = decodedToken?.value?.sub;
97
+ let idUser = decodedToken?.value?.sub
98
98
  if (isOtp.value && userInfos?.uid) {
99
- idUser = userInfos?.uid;
99
+ idUser = userInfos?.uid
100
100
  }
101
101
  const updatePasswordPayload = {
102
102
  data: {
103
103
  type: "users",
104
104
  id: idUser,
105
105
  attributes: {
106
- password: password.value,
107
- },
108
- },
109
- };
106
+ password: password.value
107
+ }
108
+ }
109
+ }
110
110
 
111
- let authorization = `Bearer ${tempToken.value}`;
111
+ let authorization = `Bearer ${tempToken.value}`
112
112
  if (isOtp.value) {
113
- authorization = `Bearer ${userInfos?.token}`;
113
+ authorization = `Bearer ${userInfos?.token}`
114
114
  }
115
115
 
116
116
  const updatePasswordHeaders = {
117
117
  headers: {
118
- Authorization: authorization,
119
- },
120
- };
121
- loading.value = true;
118
+ Authorization: authorization
119
+ }
120
+ }
121
+ loading.value = true
122
122
 
123
123
  patch(
124
124
  AUTH_SERVER_UPDATE_PASSWORD_ROUTE.replace(":userId", idUser),
@@ -126,13 +126,13 @@ export function useResetPassword() {
126
126
  updatePasswordHeaders
127
127
  )
128
128
  .then(() => {
129
- loading.value = false;
130
- passwordUpdated.value = true;
131
- localStorage.removeItem("emailResetPassword");
132
- localStorage.removeItem("userInfos");
129
+ loading.value = false
130
+ passwordUpdated.value = true
131
+ localStorage.removeItem("emailResetPassword")
132
+ localStorage.removeItem("userInfos")
133
133
  })
134
134
  .catch(() => {
135
- loading.value = false;
135
+ loading.value = false
136
136
  $q.notify({
137
137
  message: t("auth.passwordRecoveryFailed"),
138
138
  color: "negative",
@@ -141,21 +141,21 @@ export function useResetPassword() {
141
141
  actions: [
142
142
  {
143
143
  color: "white",
144
- icon: ionCloseOutline,
145
- },
146
- ],
147
- });
148
- });
149
- };
144
+ icon: ionCloseOutline
145
+ }
146
+ ]
147
+ })
148
+ })
149
+ }
150
150
 
151
151
  const goToLoginPage = () => {
152
- router.push(LOCAL_LOGIN_ROUTE);
153
- };
152
+ router.push(LOCAL_LOGIN_ROUTE)
153
+ }
154
154
 
155
155
  onMounted(() => {
156
156
  if (!isOtp.value) {
157
- let key = $route.query.key as string;
158
- const { decoded, email, tmpToken } = decodeKey(key);
157
+ const key = $route.query.key as string
158
+ const { decoded, email, tmpToken } = decodeKey(key)
159
159
 
160
160
  if (!decoded) {
161
161
  return $q.notify({
@@ -166,25 +166,25 @@ export function useResetPassword() {
166
166
  actions: [
167
167
  {
168
168
  color: "white",
169
- icon: ionCloseOutline,
170
- },
171
- ],
172
- });
169
+ icon: ionCloseOutline
170
+ }
171
+ ]
172
+ })
173
173
  }
174
174
 
175
175
  const tmpAuthPayload = {
176
176
  auth: {
177
177
  email: email,
178
- token: tmpToken,
179
- },
180
- };
178
+ token: tmpToken
179
+ }
180
+ }
181
181
 
182
182
  post(AUTH_SERVER_SIGNING_ROUTE, tmpAuthPayload)
183
- .then((response) => {
184
- tempToken.value = response.data.jwt;
185
- if (!tempToken.value) throw "Error reading the temporary token";
183
+ .then((response: { data: { jwt: any } }) => {
184
+ tempToken.value = response.data.jwt
185
+ if (!tempToken.value) throw "Error reading the temporary token"
186
186
  })
187
- .catch((error) => {
187
+ .catch((error: { response: { status: number } }) => {
188
188
  if (error.response) {
189
189
  // Request made and server responded
190
190
  if (error.response.status === 404) {
@@ -199,7 +199,7 @@ export function useResetPassword() {
199
199
  icon: ionCloseOutline,
200
200
  },
201
201
  ],
202
- });
202
+ })
203
203
  }
204
204
  }
205
205
  return $q.notify({
@@ -210,13 +210,13 @@ export function useResetPassword() {
210
210
  actions: [
211
211
  {
212
212
  color: "white",
213
- icon: ionCloseOutline,
214
- },
215
- ],
216
- });
217
- });
213
+ icon: ionCloseOutline
214
+ }
215
+ ]
216
+ })
217
+ })
218
218
  }
219
- });
219
+ })
220
220
 
221
221
  return {
222
222
  password,
@@ -233,5 +233,5 @@ export function useResetPassword() {
233
233
  ionEyeOffOutline,
234
234
  ionLockClosedOutline,
235
235
  },
236
- };
236
+ }
237
237
  }
package/src/index.js CHANGED
@@ -1,42 +1,42 @@
1
- "use strict";
2
- const path = require("path");
1
+ "use strict"
2
+ const path = require("path")
3
3
  function extendConf(conf) {
4
- const requiredPlugins = ["Notify"];
4
+ const requiredPlugins = ["Notify"]
5
5
 
6
6
  requiredPlugins.forEach((plugin) => {
7
7
  if (!conf.framework.plugins.includes(plugin)) {
8
- conf.framework.plugins.push(plugin);
8
+ conf.framework.plugins.push(plugin)
9
9
  }
10
- });
10
+ })
11
11
 
12
- conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/register.ts");
12
+ conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/register.ts")
13
13
 
14
- conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/store.ts");
14
+ conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/store.ts")
15
15
 
16
- conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/router.ts");
16
+ conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/router.ts")
17
17
 
18
18
  conf.boot.push(
19
19
  "~@sowell/quasar-app-extension-auth/src/boot/router-guards.ts"
20
- );
21
- conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/axios.ts");
20
+ )
21
+ conf.boot.push("~@sowell/quasar-app-extension-auth/src/boot/axios.ts")
22
22
 
23
- conf.build.transpileDependencies.push(/quasar-app-extension-auth[\\/]src/);
23
+ conf.build.transpileDependencies.push(/quasar-app-extension-auth[\\/]src/)
24
24
 
25
- console.log("Boot sowell auth");
25
+ console.log("Boot sowell auth")
26
26
  }
27
27
  const chainWebpack = (ctx, chain) => {
28
28
  chain.resolve.alias.set(
29
29
  "@sowell/auth",
30
30
  path.resolve(__dirname, "./components")
31
- );
31
+ )
32
32
  chain.resolve.alias.set(
33
33
  "composables",
34
34
  path.resolve(__dirname, "./composables")
35
- );
36
- };
35
+ )
36
+ }
37
37
  module.exports = function (api) {
38
- api.compatibleWith("quasar", "^2.0.0");
39
- api.compatibleWith("@quasar/app", "^3.0.0");
40
- api.chainWebpack((chain) => chainWebpack(api.ctx, chain));
41
- api.extendQuasarConf(extendConf);
42
- };
38
+ api.compatibleWith("quasar", "^2.8.0")
39
+ api.compatibleWith("@quasar/app-webpack", "^3.0.0")
40
+ api.chainWebpack((chain) => chainWebpack(api.ctx, chain))
41
+ api.extendQuasarConf(extendConf)
42
+ }
@@ -1,10 +1,10 @@
1
- import { AxiosInstance } from "axios";
2
- import { inject } from "vue";
1
+ import { AxiosInstance } from "axios"
2
+ import { inject } from "vue"
3
3
 
4
4
  export const $api = (): AxiosInstance => {
5
- const $api = inject<AxiosInstance>("$api");
5
+ const $api = inject<AxiosInstance>("$api")
6
6
  if ($api == undefined) {
7
- throw Error("Could not inject api");
7
+ throw Error("Could not inject api")
8
8
  }
9
- return $api;
9
+ return $api
10
10
  };
@@ -1,4 +1,4 @@
1
- export * from "./api";
2
- export * from "./prompts";
3
- export * from "./router";
4
- export * from './states'
1
+ export * from "./api"
2
+ export * from "./prompts"
3
+ export * from "./router"
4
+ export * from "./states"
@@ -1,29 +1,29 @@
1
- import { inject } from "vue";
1
+ import { inject } from "vue"
2
2
  export interface PromptsInterface {
3
- APP_SERVER_BASE_URL: string;
4
- LOCAL_LOGIN_ROUTE: string;
5
- LOCAL_SUCCESS_REDIRECTION_ROUTE: string;
6
- LOCAL_CHECK_CODE_ROUTE: string;
7
- LOCAL_UPDATE_PASSWORD_ROUTE: string;
8
- AUTH_SERVER_BASE_URL: string;
9
- AUTH_SERVER_SIGNING_ROUTE: string;
10
- AUTH_SERVER_RESET_PASSWORD_ROUTE: string;
11
- AUTH_SERVER_UPDATE_PASSWORD_ROUTE: string;
12
- AUTH_TYPE: string;
13
- X_REQUESTED_ROLES: string;
14
- WELCOME_TITLE: string;
15
- WELCOME_SUBTITLE: string;
16
- IS_OTP: string;
17
- LOCAL_OTP_ROUTE: string;
18
- AUTH_SERVER_VERIFY_OTP: string;
19
- UI_PAGE: string;
20
- APP_VERSION: string;
21
- USE_SSO: boolean;
3
+ APP_SERVER_BASE_URL: string
4
+ LOCAL_LOGIN_ROUTE: string
5
+ LOCAL_SUCCESS_REDIRECTION_ROUTE: string
6
+ LOCAL_CHECK_CODE_ROUTE: string
7
+ LOCAL_UPDATE_PASSWORD_ROUTE: string
8
+ AUTH_SERVER_BASE_URL: string
9
+ AUTH_SERVER_SIGNING_ROUTE: string
10
+ AUTH_SERVER_RESET_PASSWORD_ROUTE: string
11
+ AUTH_SERVER_UPDATE_PASSWORD_ROUTE: string
12
+ AUTH_TYPE: string
13
+ X_REQUESTED_ROLES: string
14
+ WELCOME_TITLE: string
15
+ WELCOME_SUBTITLE: string
16
+ IS_OTP: string
17
+ LOCAL_OTP_ROUTE: string
18
+ AUTH_SERVER_VERIFY_OTP: string
19
+ UI_PAGE: string
20
+ APP_VERSION: string
21
+ USE_SSO: boolean
22
22
  }
23
23
  export const $prompts = (): PromptsInterface => {
24
- const $prompts = inject<Record<"@sowell/auth", PromptsInterface>>("$prompts");
24
+ const $prompts = inject<Record<"@sowell/auth", PromptsInterface>>("$prompts")
25
25
  if ($prompts == undefined) {
26
- throw Error("Could not inject prompts");
26
+ throw Error("Could not inject prompts")
27
27
  }
28
- return $prompts["@sowell/auth"];
29
- };
28
+ return $prompts["@sowell/auth"]
29
+ }
@@ -1,10 +1,10 @@
1
- import { inject } from "vue";
2
- import { Router } from "vue-router";
1
+ import { inject } from "vue"
2
+ import { Router } from "vue-router"
3
3
 
4
4
  export const $router = (): Router => {
5
- const $router = inject<Router>("$router");
5
+ const $router = inject<Router>("$router")
6
6
  if ($router == undefined) {
7
- throw Error("Could not inject router");
7
+ throw Error("Could not inject router")
8
8
  }
9
- return $router;
10
- };
9
+ return $router
10
+ }
@@ -1,112 +1,112 @@
1
- import { inject } from "vue";
2
- import { Store } from "pinia";
3
- import { AxiosResponse } from "axios";
4
- import { $prompts } from "../injects";
1
+ import { inject } from "vue"
2
+ import { Store } from "pinia"
3
+ import { AxiosResponse } from "axios"
4
+ import { $prompts } from "../injects"
5
5
 
6
6
  export interface AuthStatePayload {
7
- company_hp: string;
8
- exp: number;
9
- gm_key: string;
10
- roles: string[];
11
- sub: number;
7
+ company_hp: string
8
+ exp: number
9
+ gm_key: string
10
+ roles: string[]
11
+ sub: number
12
12
  }
13
13
 
14
14
  export interface AuthState {
15
- raw?: string;
16
- payload?: AuthStatePayload;
15
+ raw?: string
16
+ payload?: AuthStatePayload
17
17
  }
18
18
  interface ConfigMobileAuth {
19
- clientId: string;
20
- scopes: ["email", "User.Read"];
21
- keyHash: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=";
19
+ clientId: string
20
+ scopes: ["email", "User.Read"]
21
+ keyHash: "2jmj7l5rSw0yVb/vlWAYkK/YBwk="
22
22
  }
23
23
 
24
24
  export interface MsalState {
25
25
  configMobile: {
26
- auth: ConfigMobileAuth;
26
+ auth: ConfigMobileAuth
27
27
  cache: {
28
- cacheLocation: "localStorage";
29
- };
30
- };
28
+ cacheLocation: "localStorage"
29
+ }
30
+ }
31
31
  configWeb: {
32
32
  auth: {
33
- clientId: string;
34
- authority: "https://login.microsoftonline.com/organizations";
35
- redirectUri: string;
36
- };
33
+ clientId: string
34
+ authority: "https://login.microsoftonline.com/organizations"
35
+ redirectUri: string
36
+ }
37
37
  cache: {
38
- cacheLocation: "localStorage";
39
- };
40
- };
41
- accessToken: string;
42
- idToken: string;
43
- email: string;
38
+ cacheLocation: "localStorage"
39
+ }
40
+ }
41
+ accessToken: string
42
+ idToken: string
43
+ email: string
44
44
  }
45
45
  export interface RequestOptions {
46
46
  headers: {
47
- "x-requested-roles"?: string;
48
- };
47
+ "x-requested-roles"?: string
48
+ }
49
49
  }
50
50
 
51
51
  export interface SignInPayload {
52
52
  auth: {
53
- email: string;
54
- password?: string;
55
- msalToken?: string;
56
- };
53
+ email: string
54
+ password?: string
55
+ msalToken?: string
56
+ }
57
57
  "device-clean"?: {
58
- manufacturer: string;
59
- model: string;
60
- platform: string;
61
- version: string;
62
- };
58
+ manufacturer: string
59
+ model: string
60
+ platform: string
61
+ version: string
62
+ }
63
63
  "app-clean"?: {
64
- versionNumber: string;
65
- };
64
+ versionNumber: string
65
+ }
66
66
  }
67
67
 
68
68
  export interface ResetPasswordPayload {
69
69
  auth: {
70
- email: string;
71
- base: string;
72
- };
70
+ email: string
71
+ base: string
72
+ }
73
73
  }
74
74
 
75
75
  export const useAuthState = (): Store<
76
76
  "auth",
77
77
  AuthState,
78
78
  {
79
- getIsValid(state: AuthState): boolean;
79
+ getIsValid(state: AuthState): boolean
80
80
  },
81
81
  {
82
82
  signin(
83
83
  data: SignInPayload,
84
84
  options: RequestOptions
85
- ): Promise<AxiosResponse>;
86
- msalSignin(): Promise<AxiosResponse>;
87
- resetPassword(data: ResetPasswordPayload): Promise<AxiosResponse>;
88
- updateRaw(value: string): void;
85
+ ): Promise<AxiosResponse>
86
+ msalSignin(): Promise<AxiosResponse>
87
+ resetPassword(data: ResetPasswordPayload): Promise<AxiosResponse>
88
+ updateRaw(value: string): void
89
89
  }
90
90
  > => {
91
- const authState = inject<Store<"auth", AuthState>>("authState");
91
+ const authState = inject<Store<"auth", AuthState>>("authState")
92
92
  if (authState == undefined) {
93
- throw Error("Could not inject authState");
93
+ throw Error("Could not inject authState")
94
94
  }
95
- return authState;
96
- };
95
+ return authState
96
+ }
97
97
 
98
98
  export const useMsalState = (): Store<
99
99
  "msal",
100
100
  MsalState,
101
101
  {
102
- signIn(): () => Promise<{ email: string; token: string }>;
103
- reset(): () => void;
102
+ signIn(): () => Promise<{ email: string; token: string }>
103
+ reset(): () => void
104
104
  }
105
105
  > => {
106
- const { USE_SSO } = $prompts();
107
- const msalState = inject<Store<"msal", MsalState>>("msalState");
106
+ const { USE_SSO } = $prompts()
107
+ const msalState = inject<Store<"msal", MsalState>>("msalState")
108
108
  if (USE_SSO && msalState == undefined) {
109
- throw Error("Could not inject msalState");
109
+ throw Error("Could not inject msalState")
110
110
  }
111
- return msalState;
112
- };
111
+ return msalState
112
+ }
@@ -1,6 +1,6 @@
1
- import { Router } from "vue-router";
2
- import { App } from "vue";
1
+ import { Router } from "vue-router"
2
+ import { App } from "vue"
3
3
  export interface BootInterface {
4
- router: Router;
5
- app: App<any>;
4
+ router: Router
5
+ app: App<any>
6
6
  }
@@ -1,2 +1,2 @@
1
- export * from "./Boot";
2
- export * from "./TokenStateInterface";
1
+ export * from "./Boot"
2
+ export * from "./TokenStateInterface"