@sowell/quasar-app-extension-auth 0.1.8 → 0.2.2

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.
Files changed (46) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +13 -13
  3. package/.gitattributes +2 -0
  4. package/.github/workflows/main.yml +22 -0
  5. package/README.md +393 -28
  6. package/package.json +34 -19
  7. package/src/boot/axios.ts +17 -0
  8. package/src/boot/register.ts +8 -0
  9. package/src/boot/router-guards.ts +25 -0
  10. package/src/boot/router.ts +20 -0
  11. package/src/boot/store.ts +10 -0
  12. package/src/components/pages/Auth.vue +227 -0
  13. package/src/components/{ResetPassword.vue → pages/ResetPassword.vue} +40 -40
  14. package/src/i18n/en-US/index.ts +23 -0
  15. package/src/i18n/fr-FR/index.ts +23 -0
  16. package/src/i18n/index.ts +7 -0
  17. package/src/index.js +29 -24
  18. package/src/injects/api.ts +10 -0
  19. package/src/injects/index.ts +4 -0
  20. package/src/injects/prompts.ts +25 -0
  21. package/src/injects/router.ts +10 -0
  22. package/src/injects/store.ts +10 -0
  23. package/src/interfaces/Boot.ts +8 -0
  24. package/src/interfaces/TokenStateInterface.ts +11 -0
  25. package/src/interfaces/index.ts +2 -0
  26. package/src/prompts.js +40 -34
  27. package/src/routes/index.ts +22 -0
  28. package/src/shims-vue.d.ts +6 -0
  29. package/src/store/index.ts +56 -0
  30. package/tsconfig.json +14 -0
  31. package/.github/workflows/publish.yml +0 -23
  32. package/.prettierrc +0 -7
  33. package/.vscode/extensions.json +0 -12
  34. package/.vscode/settings.json +0 -22
  35. package/jsconfig.json +0 -7
  36. package/package-lock.json +0 -2344
  37. package/src/boot/axios.js +0 -19
  38. package/src/boot/navigation-guards.js +0 -16
  39. package/src/boot/register.js +0 -45
  40. package/src/components/Auth.vue +0 -275
  41. package/src/components/ResetCode.vue +0 -137
  42. package/src/components/prompt.js +0 -38
  43. package/src/config/setupHeaders.js +0 -6
  44. package/src/install.js +0 -10
  45. package/src/templates/.gitkeep +0 -0
  46. package/src/uninstall.js +0 -10
package/src/boot/axios.js DELETED
@@ -1,19 +0,0 @@
1
- import axios from "axios"
2
- // FIXME: find another way to call this path
3
- import prompts from "../../../../../quasar.extensions.json"
4
- import { headers } from "setupHeaders"
5
-
6
- const {
7
- "@sowell/auth": { auth_server_base_url }
8
- } = prompts
9
-
10
- const api = axios.create({
11
- baseURL: auth_server_base_url,
12
- headers: headers
13
- })
14
-
15
- export default ({ app }) => {
16
- app.config.globalProperties.$api = api
17
- }
18
-
19
- export { api }
@@ -1,16 +0,0 @@
1
- // FIXME: find another way to call this path
2
- import prompts from "../../../../../quasar.extensions.json"
3
-
4
- export default ({ router, store }) => {
5
- const { "@sowell/auth": { local_login_route, local_check_code_route }} = prompts
6
- router.beforeEach((to, from, next) => {
7
- const isAuthenticated = store.state.auth.token !== null ? true : false
8
- if (!isAuthenticated && to.path !== local_login_route && to.path !== local_check_code_route) {
9
- next(local_login_route)
10
- }
11
- else {
12
- next()
13
-
14
- }
15
- })
16
- }
@@ -1,45 +0,0 @@
1
- import { boot } from "quasar/wrappers"
2
-
3
- // FIXME: find another way to call this path
4
- import prompts from "../../../../../quasar.extensions.json"
5
- import { i18n } from "../../../../../src/boot/i18n.js"
6
-
7
- export default boot(({ app, router }) => {
8
- let { routes } = router.options
9
- let routeData = routes.find((r) => r.path === "/")
10
- app.provide("prompts", prompts)
11
- app.provide("i18n", i18n.global)
12
-
13
- const {
14
- "@sowell/auth": {
15
- local_login_route,
16
- local_check_code_route,
17
- local_update_password_route
18
- }
19
- } = prompts
20
-
21
- const currentRoutes = routeData.children.map((route) => route.path)
22
-
23
- const newRoutes = [
24
- {
25
- path: local_login_route,
26
- component: () => import("../components/Auth")
27
- },
28
- {
29
- path: local_check_code_route,
30
- component: () => import("../components/ResetCode")
31
- },
32
- {
33
- path: local_update_password_route,
34
- component: () => import("../components/ResetPassword")
35
- }
36
- ]
37
-
38
- routeData.children = []
39
- for (let route of newRoutes) {
40
- if (!currentRoutes.includes(route.path)) {
41
- routeData.children.push(route)
42
- }
43
- }
44
- router.addRoute(routeData)
45
- })
@@ -1,275 +0,0 @@
1
- <template>
2
- <q-page class="flex flex-center">
3
- <q-card square>
4
- <q-card-section>
5
- <div class="text-h5 text-center head">
6
- {{ $t("auth.title") }}
7
- </div>
8
- </q-card-section>
9
-
10
- <q-form class="q-gutter-md" @submit="onSubmit">
11
- <q-card-section>
12
- <q-input
13
- id="email"
14
- v-model.trim="emailOrPhone"
15
- type="email"
16
- :label="$t('auth.email')"
17
- :rules="validations['emailOrPhone']"
18
- lazy-rules
19
- autofocus
20
- rounded
21
- outlined
22
- dense
23
- class="full-width q-mb-md"
24
- />
25
- <q-input
26
- id="password"
27
- v-model="password"
28
- :type="showPassword ? 'text' : 'password'"
29
- :label="$t('auth.password')"
30
- :rules="validations['password']"
31
- lazy-rules
32
- rounded
33
- outlined
34
- dense
35
- class="full-width q-mb-md"
36
- >
37
- <template #append>
38
- <q-icon
39
- :name="showPassword ? 'visibility' : 'visibility_off'"
40
- class="cursor-pointer"
41
- @click="showPassword = !showPassword"
42
- />
43
- </template>
44
- </q-input>
45
- </q-card-section>
46
- <div class="forgottenPass">
47
- <q-btn
48
- @click="forgottenPassword = true"
49
- no-caps
50
- flat
51
- :label="$t('auth.forgottenPassword')"
52
- />
53
- </div>
54
- <q-card-actions>
55
- <q-btn
56
- rounded
57
- :label="$t('auth.login')"
58
- color="primary"
59
- :loading="loading"
60
- type="submit"
61
- class="full-width"
62
- />
63
- </q-card-actions>
64
- </q-form>
65
- </q-card>
66
- <div>
67
- <q-dialog v-model="forgottenPassword" persistent>
68
- <q-card style="min-width: 350px">
69
- <q-card-section>
70
- <p class="resetPasswordTitle">
71
- {{ $t("auth.tapEmail") }}
72
- </p>
73
- </q-card-section>
74
-
75
- <q-card-section class="q-pt-none">
76
- <q-input
77
- v-model="emailResetPassword"
78
- dense
79
- rounded
80
- outlined
81
- :placeholder="$t('auth.email')"
82
- autofocus
83
- />
84
- </q-card-section>
85
-
86
- <q-card-actions align="right">
87
- <q-btn
88
- outline
89
- rounded
90
- :label="$t('common.cancel')"
91
- class="btn-min"
92
- v-close-popup
93
- />
94
- <q-btn
95
- rounded
96
- color="primary"
97
- :label="$t('common.send')"
98
- class="btn-min"
99
- @click="resetPassword"
100
- />
101
- </q-card-actions>
102
- </q-card>
103
- </q-dialog>
104
- </div>
105
- </q-page>
106
- </template>
107
-
108
- <script>
109
- import { useStore } from "vuex"
110
- import { useQuasar } from "quasar"
111
- import { useRouter } from "vue-router"
112
- import { ref, onMounted, defineComponent, inject } from "vue"
113
- import isEmail from "validator/es/lib/isEmail"
114
- import prompts from "./prompt.js"
115
- import { api } from "../boot/axios"
116
-
117
- export default defineComponent({
118
- name: "Auth",
119
-
120
- setup() {
121
- const i18n = inject("i18n")
122
- const {
123
- local_success_redirection_route,
124
- local_check_code_route,
125
- auth_server_signing_route,
126
- auth_server_reset_password_route,
127
- auth_type,
128
- vuex_set_token_mutation,
129
- vuex_clear_token_mutation,
130
- vuex_set_infos_user_mutation,
131
- vuex_get_token_getter
132
- } = prompts()
133
- const store = useStore()
134
- const $q = useQuasar()
135
- const router = useRouter()
136
- const phoneRegex = /\+.[0-9]/
137
- const emailOrPhone = ref("")
138
- const password = ref("")
139
- const loading = ref(false)
140
- const showPassword = ref(false)
141
- const forgottenPassword = ref(false)
142
- const emailResetPassword = ref("")
143
-
144
- onMounted(() => {
145
- if (store.state.auth.token) {
146
- router.replace(local_success_redirection_route)
147
- }
148
- })
149
-
150
- const validations = {
151
- emailOrPhone: [
152
- (val) => !!val || i18n.t("auth.emailPresenceError"),
153
- (val) =>
154
- isEmail(val) ||
155
- phoneRegex.test(val) ||
156
- i18n.t("auth.emailValidationError")
157
- ],
158
- password: [(val) => !!val || i18n.t("auth.passwordPresenceError")]
159
- }
160
-
161
- const resetPassword = async () => {
162
- let data = null
163
- if (isEmail(emailResetPassword.value)) {
164
- store.commit(vuex_set_infos_user_mutation, emailResetPassword.value)
165
- data = {
166
- email: emailResetPassword.value
167
- }
168
- } else if (phoneRegex.test(emailResetPassword.value)) {
169
- store.commit(vuex_set_infos_user_mutation, emailResetPassword.value)
170
- data = {
171
- phone_number: emailResetPassword.value
172
- }
173
- }
174
- await api
175
- .post(auth_server_reset_password_route, data)
176
- .then(() => {
177
- $q.notify({
178
- message: i18n.t("auth.emailSent"),
179
- color: "positive",
180
- position: "top"
181
- })
182
- router.push(local_check_code_route)
183
- })
184
- .catch(() => {
185
- $q.notify({
186
- message: i18n("auth.emailNotRecognize"),
187
- color: "negative",
188
- position: "top"
189
- })
190
- })
191
- }
192
-
193
- const onSubmit = async () => {
194
- loading.value = true
195
- let data = null
196
- if (isEmail(emailOrPhone.value)) {
197
- data = {
198
- email: emailOrPhone.value,
199
- password: password.value
200
- }
201
- } else if (phoneRegex.test(emailOrPhone.value)) {
202
- data = {
203
- phone_number: emailOrPhone.value,
204
- password: password.value
205
- }
206
- }
207
- await api
208
- .post(auth_server_signing_route, data)
209
- .then(async function (response) {
210
- const { data } = response
211
- if (response.status == "201") {
212
- store.commit(vuex_set_token_mutation, data.token)
213
- api.defaults.headers.Authorization = `${auth_type} ${store.getters[vuex_get_token_getter]}`
214
- router.push(local_success_redirection_route)
215
- } else {
216
- store.commit(vuex_clear_token_mutation)
217
- api.defaults.headers.Authorization = ""
218
- }
219
- loading.value = false
220
- })
221
- .catch(() => {
222
- loading.value = false
223
- store.commit("auth/clearToken")
224
- api.defaults.headers.Authorization = ""
225
- $q.notify({
226
- message: i18n.t("auth.loginFailed"),
227
- color: "negative",
228
- position: "top"
229
- })
230
- })
231
- }
232
-
233
- return {
234
- emailOrPhone,
235
- password,
236
- loading,
237
- showPassword,
238
- validations,
239
- onSubmit,
240
- forgottenPassword,
241
- emailResetPassword,
242
- resetPassword
243
- }
244
- }
245
- })
246
- </script>
247
-
248
- <style scoped>
249
- .head,
250
- .q-page {
251
- opacity: 0.7;
252
- }
253
-
254
- .q-card {
255
- width: 400px;
256
- padding: 50px;
257
- }
258
-
259
- .forgottenPass {
260
- margin-top: 0 !important;
261
- margin-left: 25px !important;
262
- cursor: pointer;
263
- color: #40c4ff;
264
- }
265
-
266
- .resetPasswordTitle {
267
- opacity: 0.7;
268
- text-align: center;
269
- font-size: 20px;
270
- }
271
-
272
- .btn-min {
273
- min-width: 100px !important;
274
- }
275
- </style>
@@ -1,137 +0,0 @@
1
- <template>
2
- <q-page class="flex flex-center">
3
- <q-card square>
4
- <q-card-section>
5
- <div class="text-h5 text-center head">
6
- {{ $t("auth.secretCodeTitle") }}
7
- </div>
8
- </q-card-section>
9
-
10
- <q-form class="q-gutter-md" @submit="onSubmit">
11
- <q-card-section>
12
- <q-input
13
- id="codeSecret"
14
- v-model="code"
15
- :rules="validations['code']"
16
- type="text"
17
- :label="$t('auth.secretCode')"
18
- lazy-rules
19
- rounded
20
- outlined
21
- dense
22
- class="full-width q-mb-md"
23
- >
24
- </q-input>
25
- </q-card-section>
26
-
27
- <q-card-actions>
28
- <q-btn
29
- rounded
30
- :label="$t('common.send')"
31
- color="primary"
32
- :loading="loading"
33
- type="submit"
34
- class="full-width"
35
- />
36
- </q-card-actions>
37
- </q-form>
38
- </q-card>
39
- </q-page>
40
- </template>
41
-
42
- <script>
43
- import { ref, onMounted, defineComponent, inject } from "vue"
44
- import { useStore } from "vuex"
45
- import { useQuasar } from "quasar"
46
- import { useRouter } from "vue-router"
47
- import isEmail from "validator/es/lib/isEmail"
48
- import prompts from "./prompt.js"
49
- import { api } from "../boot/axios"
50
-
51
- export default defineComponent({
52
- name: "ResetCode",
53
-
54
- setup() {
55
- const i18n = inject("i18n")
56
- const store = useStore()
57
- const $q = useQuasar()
58
- const router = useRouter()
59
- const phoneRegex = /\+.[0-9]/
60
- const code = ref("")
61
- const loading = ref(false)
62
- const {
63
- auth_server_signing_route,
64
- local_update_password_route,
65
- auth_type,
66
- local_success_redirection_route,
67
- vuex_set_token_mutation,
68
- vuex_get_token_getter,
69
- vuex_get_infos_user_getter
70
- } = prompts()
71
-
72
- const validations = {
73
- code: [(val) => !!val || i18n.t("auth.secretCodePresenceError")]
74
- }
75
-
76
- onMounted(() => {
77
- if (store.state.auth.token) {
78
- router.replace(local_success_redirection_route)
79
- }
80
- })
81
-
82
- function onSubmit() {
83
- let data = {}
84
- if (isEmail(store.getters[vuex_get_infos_user_getter])) {
85
- data = {
86
- email: store.getters[vuex_get_infos_user_getter],
87
- password_recovery_code: code.value
88
- }
89
- } else if (phoneRegex.text(store.getters[vuex_get_infos_user_getter])) {
90
- data = {
91
- phone_number: store.getters[vuex_get_infos_user_getter],
92
- password_recovery_code: code.value
93
- }
94
- }
95
-
96
- api
97
- .post(auth_server_signing_route, data)
98
- .then(({ data }) => {
99
- $q.notify({
100
- message: i18n.t("auth.secretCodeSuccess"),
101
- color: "positive",
102
- position: "top"
103
- })
104
- store.commit(vuex_set_token_mutation, data.token)
105
- api.defaults.headers.Authorization = `${auth_type} ${store.getters[vuex_get_token_getter]}`
106
- router.push(local_update_password_route)
107
- })
108
- .catch(() => {
109
- $q.notify({
110
- message: i18n.t("auth.secretCodeFailed"),
111
- color: "negative",
112
- position: "top"
113
- })
114
- })
115
- }
116
-
117
- return {
118
- code,
119
- loading,
120
- validations,
121
- onSubmit
122
- }
123
- }
124
- })
125
- </script>
126
-
127
- <style scoped>
128
- .head,
129
- .q-page {
130
- opacity: 0.7;
131
- }
132
-
133
- .q-card {
134
- width: 400px;
135
- padding: 50px;
136
- }
137
- </style>
@@ -1,38 +0,0 @@
1
- import { inject } from "vue"
2
- export default function prompts() {
3
- const {
4
- "@sowell/auth": {
5
- local_login_route,
6
- local_success_redirection_route,
7
- local_check_code_route,
8
- local_update_password_route,
9
- auth_server_base_url,
10
- auth_server_signing_route,
11
- auth_server_reset_password_route,
12
- auth_server_update_password_route,
13
- auth_type,
14
- vuex_set_token_mutation,
15
- vuex_clear_token_mutation,
16
- vuex_set_infos_user_mutation,
17
- vuex_get_token_getter,
18
- vuex_get_infos_user_getter
19
- }
20
- } = inject("prompts")
21
-
22
- return {
23
- local_login_route,
24
- local_success_redirection_route,
25
- local_check_code_route,
26
- local_update_password_route,
27
- auth_server_base_url,
28
- auth_server_signing_route,
29
- auth_server_reset_password_route,
30
- auth_server_update_password_route,
31
- auth_type,
32
- vuex_set_token_mutation,
33
- vuex_clear_token_mutation,
34
- vuex_set_infos_user_mutation,
35
- vuex_get_token_getter,
36
- vuex_get_infos_user_getter
37
- }
38
- }
@@ -1,6 +0,0 @@
1
- let headers = null
2
- const setup_headers = (payload) => {
3
- headers = payload
4
- }
5
-
6
- export { setup_headers, headers }
package/src/install.js DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Quasar App Extension install script
3
- *
4
- * Docs: https://quasar.dev/app-extensions/development-guide/install-api
5
- * API: https://github.com/quasarframework/quasar/blob/master/app/lib/app-extension/InstallAPI.js
6
- */
7
-
8
- module.exports = function () {
9
- //
10
- }
File without changes
package/src/uninstall.js DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Quasar App Extension uninstall script
3
- *
4
- * Docs: https://quasar.dev/app-extensions/development-guide/uninstall-api
5
- * API: https://github.com/quasarframework/quasar/blob/master/app/lib/app-extension/UninstallAPI.js
6
- */
7
-
8
- module.exports = function () {
9
- //
10
- }