@drax/identity-front 0.0.9 → 0.0.11
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 +5 -18
- package/src/errors/BadCredentialsError.ts +8 -0
- package/src/{core/factories → factories}/providers/AuthProviderFactory.ts +8 -8
- package/src/{core/factories → factories}/system/AuthSystemFactory.ts +2 -2
- package/src/helpers/AuthHelper.ts +32 -0
- package/src/helpers/JwtDecodeHelper.ts +79 -0
- package/src/i18n/identity-permissions-i18n.ts +43 -0
- package/src/i18n/identity-role-i18n.ts +27 -0
- package/src/i18n/identity-user-i18n.ts +59 -0
- package/src/i18n/identity-validation-i18n.ts +29 -0
- package/src/i18n/index.ts +10 -0
- package/src/index.ts +48 -12
- package/src/interfaces/IAuthProvider.ts +12 -0
- package/src/interfaces/IAuthUser.ts +15 -0
- package/src/interfaces/ILoginResponse.ts +5 -0
- package/src/interfaces/IRole.ts +10 -0
- package/src/interfaces/IRoleProvider.ts +13 -0
- package/src/interfaces/IUser.ts +39 -0
- package/src/interfaces/IUserProvider.ts +14 -0
- package/src/providers/gql/AuthGqlProvider.ts +59 -0
- package/src/providers/gql/RoleGqlProvider.ts +74 -0
- package/src/providers/gql/UserGqlProvider.ts +63 -0
- package/src/providers/rest/AuthRestProvider.ts +51 -0
- package/src/providers/rest/RoleRestProvider.ts +61 -0
- package/src/providers/rest/UserRestProvider.ts +55 -0
- package/src/system/AuthSystem.ts +35 -0
- package/src/system/RoleSystem.ts +43 -0
- package/src/system/UserSystem.ts +41 -0
- package/src/assets/base.css +0 -86
- package/src/assets/logo.svg +0 -1
- package/src/assets/main.css +0 -35
- package/src/components/HelloWorld.vue +0 -41
- package/src/components/IdentityLogin/IdentityLogin.vue +0 -82
- package/src/components/__tests__/IdentityLogin.spec.ts +0 -11
- package/src/components/icons/IconCommunity.vue +0 -7
- package/src/components/icons/IconDocumentation.vue +0 -0
- package/src/components/icons/IconEcosystem.vue +0 -0
- package/src/components/icons/IconSupport.vue +0 -0
- package/src/components/icons/IconTooling.vue +0 -0
- package/src/core/interfaces/IAuthProviderInterface.ts +0 -5
- package/src/core/providers/gql/AuthGqlProvider.ts +0 -19
- package/src/core/providers/rest/AuthRestProvider.ts +0 -19
- package/src/core/system/AuthSystem.ts +0 -21
- package/src/stores/auth/AuthStore.ts +0 -19
- package/src/stores/counter.ts +0 -12
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.11",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -24,22 +24,13 @@
|
|
|
24
24
|
"format": "prettier --write src/"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@drax/common-front": "^0.0.
|
|
28
|
-
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"pinia": "^2.1.7",
|
|
31
|
-
"vue": "^3.4.21",
|
|
32
|
-
"vuetify": "^3.6.4"
|
|
27
|
+
"@drax/common-front": "^0.0.11"
|
|
33
28
|
},
|
|
34
29
|
"devDependencies": {
|
|
35
30
|
"@rushstack/eslint-patch": "^1.8.0",
|
|
36
31
|
"@tsconfig/node20": "^20.1.4",
|
|
37
|
-
"@types/jsdom": "^21.1.
|
|
32
|
+
"@types/jsdom": "^21.1.7",
|
|
38
33
|
"@types/node": "^20.12.5",
|
|
39
|
-
"@vitejs/plugin-vue": "^5.0.4",
|
|
40
|
-
"@vue/eslint-config-prettier": "^9.0.0",
|
|
41
|
-
"@vue/eslint-config-typescript": "^13.0.0",
|
|
42
|
-
"@vue/test-utils": "^2.4.5",
|
|
43
34
|
"@vue/tsconfig": "^0.5.1",
|
|
44
35
|
"cypress": "^13.7.2",
|
|
45
36
|
"eslint": "^8.57.0",
|
|
@@ -47,17 +38,13 @@
|
|
|
47
38
|
"eslint-plugin-vue": "^9.23.0",
|
|
48
39
|
"jsdom": "^24.0.0",
|
|
49
40
|
"npm-run-all2": "^6.1.2",
|
|
50
|
-
"pinia": "^2.1.7",
|
|
51
41
|
"prettier": "^3.2.5",
|
|
52
42
|
"start-server-and-test": "^2.0.3",
|
|
53
43
|
"typescript": "~5.4.0",
|
|
54
44
|
"vite": "^5.2.8",
|
|
55
45
|
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
56
46
|
"vite-plugin-dts": "^3.9.1",
|
|
57
|
-
"vitest": "^1.4.0"
|
|
58
|
-
"vue": "^3.4.21",
|
|
59
|
-
"vue-tsc": "^2.0.11",
|
|
60
|
-
"vuetify": "^3.6.4"
|
|
47
|
+
"vitest": "^1.4.0"
|
|
61
48
|
},
|
|
62
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "647b220cda1aa372d63b93f7120ae718cc257494"
|
|
63
50
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type {IGqlClient, IHttpClient} from '@drax/common-front'
|
|
2
|
+
import {HttpGqlClientFactory, HttpFetchClientFactory} from '@drax/common-front';
|
|
3
|
+
import type {IAuthProvider} from "@/core/interfaces/IAuthProvider";
|
|
4
4
|
import AuthRestProvider from "@/core/providers/rest/AuthRestProvider";
|
|
5
5
|
import AuthGqlProvider from "@/core/providers/gql/AuthGqlProvider";
|
|
6
6
|
class AuthProviderFactory{
|
|
7
|
-
static create(type: string = 'rest'):
|
|
7
|
+
static create(type: string = 'rest'): IAuthProvider {
|
|
8
8
|
if (type === 'gql') {
|
|
9
9
|
return AuthProviderFactory.createGql()
|
|
10
10
|
}
|
|
11
11
|
return AuthProviderFactory.createRest()
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
static createGql():
|
|
15
|
-
const gqlClient:
|
|
14
|
+
static createGql(): IAuthProvider {
|
|
15
|
+
const gqlClient: IGqlClient = HttpGqlClientFactory.create('/graphql')
|
|
16
16
|
return new AuthGqlProvider(gqlClient)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
static createRest():
|
|
19
|
+
static createRest(): IAuthProvider {
|
|
20
20
|
const baseUrl = import.meta.env.API_URL ? import.meta.env.API_URL : ''
|
|
21
21
|
console.log("baseUrl",baseUrl)
|
|
22
22
|
const baseHeaders = new Headers()
|
|
23
|
-
const httpClient:
|
|
23
|
+
const httpClient: IHttpClient = HttpFetchClientFactory.create(baseUrl,baseHeaders)
|
|
24
24
|
return new AuthRestProvider(httpClient)
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import AuthSystem from "@/core/system/AuthSystem";
|
|
2
|
-
import type {
|
|
2
|
+
import type {IAuthProvider} from "@/core/interfaces/IAuthProvider";
|
|
3
3
|
import AuthRestProviderFactory from "@/core/factories/providers/AuthProviderFactory";
|
|
4
4
|
|
|
5
5
|
class AuthSystemFactory {
|
|
6
6
|
|
|
7
7
|
static create(type: string = 'rest'): AuthSystem {
|
|
8
|
-
const provider:
|
|
8
|
+
const provider: IAuthProvider = AuthRestProviderFactory.create(type)
|
|
9
9
|
|
|
10
10
|
return new AuthSystem(provider)
|
|
11
11
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {jwtDecodeHelper} from './JwtDecodeHelper.js'
|
|
2
|
+
import type {JwtPayload} from './JwtDecodeHelper'
|
|
3
|
+
|
|
4
|
+
class AuthHelper {
|
|
5
|
+
|
|
6
|
+
static isJWTValid(accessToken: string) {
|
|
7
|
+
try {
|
|
8
|
+
|
|
9
|
+
if (!accessToken) return false
|
|
10
|
+
|
|
11
|
+
let payload = jwtDecodeHelper(accessToken) as JwtPayload
|
|
12
|
+
|
|
13
|
+
if (!payload.exp) return false
|
|
14
|
+
|
|
15
|
+
let dateToken = new Date(payload.exp * 1000)
|
|
16
|
+
|
|
17
|
+
let now = new Date()
|
|
18
|
+
if (now > dateToken) return false
|
|
19
|
+
|
|
20
|
+
return true
|
|
21
|
+
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error("isJWTValid", err)
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default AuthHelper
|
|
32
|
+
export {AuthHelper}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export class InvalidTokenError extends Error {
|
|
2
|
+
}
|
|
3
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
4
|
+
|
|
5
|
+
export interface JwtDecodeOptions {
|
|
6
|
+
header?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface JwtHeader {
|
|
9
|
+
typ?: string;
|
|
10
|
+
alg?: string;
|
|
11
|
+
kid?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface JwtPayload {
|
|
14
|
+
iss?: string;
|
|
15
|
+
sub?: string;
|
|
16
|
+
aud?: string[] | string;
|
|
17
|
+
exp?: number;
|
|
18
|
+
nbf?: number;
|
|
19
|
+
iat?: number;
|
|
20
|
+
jti?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function b64DecodeUnicode(str:string) {
|
|
25
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
26
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
27
|
+
if (code.length < 2) {
|
|
28
|
+
code = "0" + code;
|
|
29
|
+
}
|
|
30
|
+
return "%" + code;
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
function base64UrlDecode(str:string) {
|
|
34
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
35
|
+
switch (output.length % 4) {
|
|
36
|
+
case 0:
|
|
37
|
+
break;
|
|
38
|
+
case 2:
|
|
39
|
+
output += "==";
|
|
40
|
+
break;
|
|
41
|
+
case 3:
|
|
42
|
+
output += "=";
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
throw new Error("base64 string is not of the correct length");
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return b64DecodeUnicode(output);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
return atob(output);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function jwtDecodeHelper(token:string, options?: JwtDecodeOptions):JwtPayload|JwtHeader {
|
|
55
|
+
if (typeof token !== "string") {
|
|
56
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
57
|
+
}
|
|
58
|
+
options || (options = {});
|
|
59
|
+
const pos = options.header === true ? 0 : 1;
|
|
60
|
+
const part = token.split(".")[pos];
|
|
61
|
+
if (typeof part !== "string") {
|
|
62
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
63
|
+
}
|
|
64
|
+
let decoded;
|
|
65
|
+
try {
|
|
66
|
+
decoded = base64UrlDecode(part);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
const errorMessage = e instanceof Error ? e.message : "unknown error";
|
|
70
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${errorMessage})`);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(decoded);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
const errorMessage = e instanceof Error ? e.message : "unknown error";
|
|
77
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${errorMessage})`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
en: {
|
|
3
|
+
permission: {
|
|
4
|
+
'user':'User',
|
|
5
|
+
'role':'Role',
|
|
6
|
+
'permissions': 'Permissions',
|
|
7
|
+
'user:view': 'View User',
|
|
8
|
+
'user:create': 'Create User',
|
|
9
|
+
'user:update': 'Edit User',
|
|
10
|
+
'user:delete': 'Delete User',
|
|
11
|
+
'user:manage': 'Manage User',
|
|
12
|
+
'role:view': 'View Role',
|
|
13
|
+
'role:create': 'Create Role',
|
|
14
|
+
'role:edit': 'Edit Role',
|
|
15
|
+
'role:delete': 'Delete Role',
|
|
16
|
+
'role:manage': 'Manage Role',
|
|
17
|
+
'role:permissions': 'Permissions',
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
es: {
|
|
22
|
+
permission: {
|
|
23
|
+
'user':'Usuario',
|
|
24
|
+
'role':'Rol',
|
|
25
|
+
'permissions': 'Permisos',
|
|
26
|
+
'user:view': 'Ver Usuario',
|
|
27
|
+
'user:create': 'Crear Usuario',
|
|
28
|
+
'user:update': 'Editar Usuario',
|
|
29
|
+
'user:delete': 'Eliminar Usuario',
|
|
30
|
+
'user:manage': 'Administrar Usuario',
|
|
31
|
+
'role:view': 'Ver Rol',
|
|
32
|
+
'role:create': 'Crear Rol',
|
|
33
|
+
'role:edit': 'Editar Rol',
|
|
34
|
+
'role:delete': 'Eliminar Rol',
|
|
35
|
+
'role:manage': 'Administrar Rol',
|
|
36
|
+
'role:permissions': 'Permisos',
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export default messages
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
en: {
|
|
3
|
+
role: {
|
|
4
|
+
name: "Name",
|
|
5
|
+
permissions: "Username",
|
|
6
|
+
readonly: "Read Only",
|
|
7
|
+
updating: "Updating Role",
|
|
8
|
+
creating: "Creating Role",
|
|
9
|
+
deleting: "Deleting Role",
|
|
10
|
+
managing: 'Managing Role',
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
es: {
|
|
14
|
+
role:{
|
|
15
|
+
name: "Nombre",
|
|
16
|
+
permissions: "Permisos",
|
|
17
|
+
readonly: "Solo lectura",
|
|
18
|
+
updating: "Actualizando Rol",
|
|
19
|
+
creating: "Creando Rol",
|
|
20
|
+
deleting: "Eliminando Rol",
|
|
21
|
+
managing: 'Gestionando Rol',
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export default messages
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
en: {
|
|
3
|
+
user: {
|
|
4
|
+
name: "Name",
|
|
5
|
+
username: "Username",
|
|
6
|
+
email: "Email",
|
|
7
|
+
password: "Password",
|
|
8
|
+
phone: "Phone",
|
|
9
|
+
avatar: "Avatar",
|
|
10
|
+
role: "Role",
|
|
11
|
+
active: "Active",
|
|
12
|
+
groups: "Groups",
|
|
13
|
+
code: "Code",
|
|
14
|
+
currentPassword: "Current Password",
|
|
15
|
+
newPassword: "New Password",
|
|
16
|
+
confirmPassword: "Confirm Password",
|
|
17
|
+
changeOwnPassword: "Change Password",
|
|
18
|
+
passwordChanged: "Password Changed",
|
|
19
|
+
updating: "Updating User",
|
|
20
|
+
creating: "Creating User",
|
|
21
|
+
deleting: "Deleting User",
|
|
22
|
+
changingPassword: "Changing User Password",
|
|
23
|
+
managing: 'Managing Users',
|
|
24
|
+
profile:'Profile',
|
|
25
|
+
login:'Login',
|
|
26
|
+
logout:'Logout'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
es: {
|
|
30
|
+
user:{
|
|
31
|
+
name: "Nombre",
|
|
32
|
+
username: "Usuario",
|
|
33
|
+
email: "Email",
|
|
34
|
+
password: "Clave",
|
|
35
|
+
phone: "Télefono",
|
|
36
|
+
avatar: "Avatar",
|
|
37
|
+
role: "Rol",
|
|
38
|
+
active: "Activo",
|
|
39
|
+
groups: "Grupos",
|
|
40
|
+
code: "Codigo",
|
|
41
|
+
currentPassword: "Clave Actual",
|
|
42
|
+
newPassword: "Nueva Clave",
|
|
43
|
+
confirmPassword: "Confirmar Clave",
|
|
44
|
+
changeOwnPassword: "Cambiar Clave",
|
|
45
|
+
passwordChanged: "Clave Cambiada",
|
|
46
|
+
updating: "Actualizando Usuario",
|
|
47
|
+
creating: "Creando Usuario",
|
|
48
|
+
deleting: "Eliminando Usuario",
|
|
49
|
+
changingPassword: "Cambiando Clave de Usuario",
|
|
50
|
+
managing: 'Administrando Usuarios',
|
|
51
|
+
profile:'Perfil',
|
|
52
|
+
login:'Iniciar Sesión',
|
|
53
|
+
logout:'Cerrar Sesión'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export default messages
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
en: {
|
|
3
|
+
validation: {
|
|
4
|
+
email: {
|
|
5
|
+
invalid: 'Invalid Email',
|
|
6
|
+
},
|
|
7
|
+
password: {
|
|
8
|
+
min8: 'Password must be at least 8 characters long',
|
|
9
|
+
max32: 'Password must be at most 32 characters long',
|
|
10
|
+
confirmed: 'Passwords do not match',
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
es: {
|
|
15
|
+
validation: {
|
|
16
|
+
email:{
|
|
17
|
+
invalid: 'Email invalido',
|
|
18
|
+
},
|
|
19
|
+
password:{
|
|
20
|
+
min8: 'La contraseña debe tener al menos 8 caracteres',
|
|
21
|
+
max32: 'La contraseña debe tener como maximo 32 caracteres',
|
|
22
|
+
confirmed: 'Las contraseñas no coinciden',
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export default messages
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import merge from 'deepmerge'
|
|
2
|
+
import identityValidationI18n from "./identity-validation-i18n.js";
|
|
3
|
+
import identityPermissionI18n from "./identity-permissions-i18n.js";
|
|
4
|
+
import identityUserI18n from "./identity-user-i18n.js";
|
|
5
|
+
import identityRoleI18n from "./identity-role-i18n.js";
|
|
6
|
+
|
|
7
|
+
const IdentityI18nMessages = merge.all([identityValidationI18n, identityUserI18n, identityRoleI18n, identityPermissionI18n])
|
|
8
|
+
|
|
9
|
+
export default IdentityI18nMessages
|
|
10
|
+
export {IdentityI18nMessages}
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,62 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import AuthSystem from "./system/AuthSystem.js"
|
|
2
|
+
import UserSystem from "./system/UserSystem.js"
|
|
3
|
+
import RoleSystem from "./system/RoleSystem.js"
|
|
4
|
+
import {AuthHelper} from "./helpers/AuthHelper.js"
|
|
5
|
+
import {jwtDecodeHelper} from "./helpers/JwtDecodeHelper.js"
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import AuthRestProvider from "./providers/rest/AuthRestProvider.js";
|
|
8
|
+
import AuthGqlProvider from "./providers/gql/AuthGqlProvider.js";
|
|
9
|
+
|
|
10
|
+
import UserRestProvider from "./providers/rest/UserRestProvider.js";
|
|
11
|
+
import UserGqlProvider from "./providers/gql/UserGqlProvider.js";
|
|
12
|
+
|
|
13
|
+
import RoleRestProvider from "./providers/rest/RoleRestProvider.js";
|
|
14
|
+
import RoleGqlProvider from "./providers/gql/RoleGqlProvider.js";
|
|
15
|
+
|
|
16
|
+
import {IdentityI18nMessages} from "./i18n/index.js"
|
|
17
|
+
|
|
18
|
+
import type {IAuthProvider} from "./interfaces/IAuthProvider"
|
|
19
|
+
import type {IUserProvider} from "./interfaces/IUserProvider"
|
|
20
|
+
import type {IRoleProvider} from "./interfaces/IRoleProvider"
|
|
21
|
+
import type {IAuthUser} from "./interfaces/IAuthUser"
|
|
22
|
+
import type {IUser, IUserCreate, IUserUpdate, IUserPassword} from "./interfaces/IUser"
|
|
23
|
+
import type {IRole} from "./interfaces/IRole"
|
|
24
|
+
import type {ILoginResponse} from "./interfaces/ILoginResponse"
|
|
8
25
|
|
|
9
26
|
export type {
|
|
10
|
-
|
|
27
|
+
IAuthProvider,
|
|
28
|
+
IUserProvider,
|
|
29
|
+
IRoleProvider,
|
|
30
|
+
IAuthUser,
|
|
31
|
+
IUser,
|
|
32
|
+
IUserCreate,
|
|
33
|
+
IUserUpdate,
|
|
34
|
+
IUserPassword,
|
|
35
|
+
IRole,
|
|
36
|
+
ILoginResponse
|
|
11
37
|
}
|
|
12
38
|
|
|
13
39
|
export {
|
|
14
|
-
//Vue Components
|
|
15
|
-
IdentityLogin,
|
|
16
|
-
|
|
17
40
|
//Providers
|
|
18
41
|
AuthRestProvider,
|
|
19
42
|
AuthGqlProvider,
|
|
20
43
|
|
|
44
|
+
UserGqlProvider,
|
|
45
|
+
UserRestProvider,
|
|
46
|
+
|
|
47
|
+
RoleGqlProvider,
|
|
48
|
+
RoleRestProvider,
|
|
49
|
+
|
|
21
50
|
//Systems
|
|
22
51
|
AuthSystem,
|
|
52
|
+
UserSystem,
|
|
53
|
+
RoleSystem,
|
|
54
|
+
|
|
55
|
+
//Helpers
|
|
56
|
+
AuthHelper,
|
|
57
|
+
jwtDecodeHelper,
|
|
58
|
+
|
|
59
|
+
//I18n
|
|
60
|
+
IdentityI18nMessages
|
|
23
61
|
|
|
24
|
-
//Stores
|
|
25
|
-
useAuthStore
|
|
26
62
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {IAuthUser} from "@/interfaces/IAuthUser";
|
|
2
|
+
import type {ILoginResponse} from "@/interfaces/ILoginResponse";
|
|
3
|
+
|
|
4
|
+
interface IAuthProvider {
|
|
5
|
+
login(username: string, password: string): Promise<ILoginResponse>
|
|
6
|
+
me(): Promise<IAuthUser>
|
|
7
|
+
logout(): void
|
|
8
|
+
changeOwnPassword(currentPassword:string, newPassword:string):Promise<boolean>
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type {IAuthProvider}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type {IRole} from "@/interfaces/IRole";
|
|
2
|
+
import type {IPaginateClient} from "@drax/common-front";
|
|
3
|
+
|
|
4
|
+
interface IRoleProvider {
|
|
5
|
+
fetchRole(): Promise<any>
|
|
6
|
+
fetchPermissions(): Promise<any>
|
|
7
|
+
paginateRole(page: number, limit: number, search:string): Promise<IPaginateClient>
|
|
8
|
+
createRole(input: IRole): Promise<any>
|
|
9
|
+
editRole(id: string, input: IRole): Promise<IRole>
|
|
10
|
+
deleteRole(id: string): Promise<any>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type {IRoleProvider}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {IRole} from "@/interfaces/IRole";
|
|
2
|
+
|
|
3
|
+
interface IUser {
|
|
4
|
+
id: string
|
|
5
|
+
name: string
|
|
6
|
+
username: string
|
|
7
|
+
email: string
|
|
8
|
+
active: boolean
|
|
9
|
+
phone: string
|
|
10
|
+
avatar: string
|
|
11
|
+
role: IRole
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface IUserCreate {
|
|
16
|
+
name: string
|
|
17
|
+
username: string
|
|
18
|
+
password: string
|
|
19
|
+
email: string
|
|
20
|
+
active: boolean
|
|
21
|
+
phone: string
|
|
22
|
+
role: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface IUserUpdate {
|
|
26
|
+
name: string
|
|
27
|
+
username: string
|
|
28
|
+
email: string
|
|
29
|
+
active: boolean
|
|
30
|
+
phone: string
|
|
31
|
+
role: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface IUserPassword {
|
|
35
|
+
newPassword: string
|
|
36
|
+
confirmPassword: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type {IUser, IUserCreate, IUserUpdate, IUserPassword}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type {IUser, IUserCreate, IUserUpdate} from "@/interfaces/IUser";
|
|
2
|
+
import type {IPaginateClient} from "@drax/common-front";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface IUserProvider {
|
|
7
|
+
paginateUser(page: number, limit: number, search?:string): Promise<IPaginateClient>
|
|
8
|
+
createUser(input: IUserCreate): Promise<IUser>
|
|
9
|
+
editUser(id: string, input: IUserUpdate): Promise<IUser>
|
|
10
|
+
deleteUser(id: string): Promise<any>
|
|
11
|
+
changeUserPassword(id: string, newPassword: string): Promise<boolean>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type {IUserProvider}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {IGqlClient} from '@drax/common-front'
|
|
2
|
+
import type {IAuthProvider} from "../../interfaces/IAuthProvider.ts";
|
|
3
|
+
import type {IAuthUser} from "../../interfaces/IAuthUser";
|
|
4
|
+
import type {ILoginResponse} from "../../interfaces/ILoginResponse";
|
|
5
|
+
|
|
6
|
+
class AuthGqlProvider implements IAuthProvider {
|
|
7
|
+
|
|
8
|
+
gqlClient: IGqlClient
|
|
9
|
+
|
|
10
|
+
constructor(gqlClient: IGqlClient) {
|
|
11
|
+
this.gqlClient = gqlClient
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setHttpClientToken(token: string): void {
|
|
15
|
+
this.gqlClient.addHeader('Authorization', `Bearer ${token}`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
removeHttpClientToken(): void {
|
|
19
|
+
this.gqlClient.removeHeader('Authorization')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
logout(): void {
|
|
23
|
+
this.removeHttpClientToken()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async login(username: string, password: string): Promise<ILoginResponse> {
|
|
27
|
+
|
|
28
|
+
const query: string = `mutation auth($input: AuthInput) { auth(input: $input) {accessToken} }`
|
|
29
|
+
const variables = {input: {username, password}}
|
|
30
|
+
let data = await this.gqlClient.mutation(query, variables)
|
|
31
|
+
const {accessToken} = data.auth
|
|
32
|
+
this.setHttpClientToken(accessToken)
|
|
33
|
+
return {accessToken}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async me(): Promise<IAuthUser> {
|
|
37
|
+
const query: string = `query me { me {id,username, email, role {id, name, permissions}} }`
|
|
38
|
+
let data = await this.gqlClient.query(query)
|
|
39
|
+
return data.me
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async changeOwnPassword(currentPassword: string, newPassword: string): Promise<boolean> {
|
|
43
|
+
const query: string = `mutation changeOwnPassword($currentPassword: String!, $newPassword: String!)
|
|
44
|
+
{ changeOwnPassword(currentPassword: $currentPassword, newPassword: $newPassword) }`
|
|
45
|
+
const variables = {currentPassword, newPassword}
|
|
46
|
+
let r = await this.gqlClient.mutation(query, variables)
|
|
47
|
+
return /true/i.test(r as string)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async changeUserPassword(currentPassword: string, newPassword: string): Promise<boolean> {
|
|
51
|
+
const query: string = `mutation changeUserPassword($userId: ID!, $newPassword: String!)
|
|
52
|
+
{ changeUserPassword(userId: $userId, newPassword: $newPassword) }`
|
|
53
|
+
const variables = {currentPassword, newPassword}
|
|
54
|
+
let r = await this.gqlClient.mutation(query, variables)
|
|
55
|
+
return /true/i.test(r as string)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default AuthGqlProvider
|