@driveflux/auth 4.0.59 → 4.0.60
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/dist/AuthProvider.js +59 -76
- package/dist/authorization/constants.js +24 -45
- package/dist/authorization/define.js +28 -57
- package/dist/authorization/fields/index.js +7 -4
- package/dist/authorization/helpers.js +8 -10
- package/dist/authorization/index.js +6 -6
- package/dist/authorization/permissions-list.js +7 -5
- package/dist/authorization/quick.js +1 -1
- package/dist/authorization/roles/admin/business-development-executive.js +7 -20
- package/dist/authorization/roles/admin/ceo.js +2 -4
- package/dist/authorization/roles/admin/common.js +2 -4
- package/dist/authorization/roles/admin/concierge.js +10 -35
- package/dist/authorization/roles/admin/customer-success-executive.js +10 -40
- package/dist/authorization/roles/admin/data-analyst.js +4 -7
- package/dist/authorization/roles/admin/designer.js +4 -7
- package/dist/authorization/roles/admin/engineer.js +4 -7
- package/dist/authorization/roles/admin/finance-executive.js +4 -11
- package/dist/authorization/roles/admin/head-of-business-development.js +4 -14
- package/dist/authorization/roles/admin/head-of-data-analytics.js +4 -14
- package/dist/authorization/roles/admin/head-of-engineering.js +6 -17
- package/dist/authorization/roles/admin/head-of-finance.js +3 -8
- package/dist/authorization/roles/admin/head-of-human-resources.js +5 -13
- package/dist/authorization/roles/admin/head-of-marketing.js +5 -17
- package/dist/authorization/roles/admin/head-of-operations.js +3 -8
- package/dist/authorization/roles/admin/head-of-product.js +6 -17
- package/dist/authorization/roles/admin/head-of-sales.js +5 -17
- package/dist/authorization/roles/admin/human-resources-executive.js +5 -12
- package/dist/authorization/roles/admin/marketing-executive.js +4 -7
- package/dist/authorization/roles/admin/product-manager.js +4 -7
- package/dist/authorization/roles/admin/sales-executive.js +8 -24
- package/dist/authorization/roles/consumer/business-admin.js +6 -19
- package/dist/authorization/roles/consumer/business-user.js +6 -18
- package/dist/authorization/roles/consumer/member.js +6 -16
- package/dist/authorization/types.js +1 -1
- package/dist/authorization/update-user-permissions.js +15 -22
- package/dist/authorization/utils.js +11 -26
- package/dist/context.js +9 -8
- package/dist/default.js +1 -1
- package/dist/server/authenticate-user.js +7 -11
- package/dist/server/cors.js +12 -23
- package/dist/server/credentials-provider.js +2 -2
- package/dist/server/next-auth.js +109 -104
- package/dist/server/prisma-adapter.js +52 -88
- package/dist/server/verfiy-token.js +24 -39
- package/dist/translations.js +4 -4
- package/dist/use-auth.js +1 -1
- package/dist/use-session.js +1 -1
- package/package.json +7 -7
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
import { prisma } from '@driveflux/db';
|
|
2
|
-
import { makeProblem, PROBLEM_CORRUPT, PROBLEM_EXPIRED, PROBLEM_INVALID_DATA } from '@driveflux/problem';
|
|
2
|
+
import { makeProblem, PROBLEM_CORRUPT, PROBLEM_EXPIRED, PROBLEM_INVALID_DATA, } from '@driveflux/problem';
|
|
3
3
|
import { Err, Ok } from '@driveflux/result';
|
|
4
|
-
export const verifyToken = async (tokenIdOrValue, verifications, option)=>{
|
|
5
|
-
const token = typeof tokenIdOrValue === 'object'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
...option?.includeUser ? {
|
|
17
|
-
include: {
|
|
18
|
-
user: true
|
|
19
|
-
}
|
|
20
|
-
} : {}
|
|
21
|
-
});
|
|
4
|
+
export const verifyToken = async (tokenIdOrValue, verifications, option) => {
|
|
5
|
+
const token = typeof tokenIdOrValue === 'object'
|
|
6
|
+
? tokenIdOrValue
|
|
7
|
+
: (await prisma.token.findFirst({
|
|
8
|
+
where: {
|
|
9
|
+
OR: [{ id: tokenIdOrValue }, { value: tokenIdOrValue }],
|
|
10
|
+
},
|
|
11
|
+
...(option?.includeUser ? { include: { user: true } } : {}),
|
|
12
|
+
}));
|
|
22
13
|
if (!token) {
|
|
23
14
|
return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token'));
|
|
24
15
|
}
|
|
25
16
|
if (token.expiresAt && token.expiresAt.getTime() < Date.now()) {
|
|
26
17
|
return new Err(makeProblem(PROBLEM_EXPIRED, 'This token has expired'));
|
|
27
18
|
}
|
|
28
|
-
if (typeof verifications?.scope !== 'undefined' &&
|
|
19
|
+
if (typeof verifications?.scope !== 'undefined' &&
|
|
20
|
+
token.scope !== verifications.scope) {
|
|
29
21
|
return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token scope'));
|
|
30
22
|
}
|
|
31
23
|
if (typeof verifications?.metadata !== 'undefined') {
|
|
32
|
-
for (const key of Object.keys(verifications.metadata)){
|
|
33
|
-
if (typeof verifications.metadata[key] !== 'undefined' &&
|
|
24
|
+
for (const key of Object.keys(verifications.metadata)) {
|
|
25
|
+
if (typeof verifications.metadata[key] !== 'undefined' &&
|
|
26
|
+
verifications.metadata[key] !== token.metadata?.[key]) {
|
|
34
27
|
return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token data'));
|
|
35
28
|
}
|
|
36
29
|
}
|
|
@@ -40,30 +33,22 @@ export const verifyToken = async (tokenIdOrValue, verifications, option)=>{
|
|
|
40
33
|
}
|
|
41
34
|
return new Ok(token);
|
|
42
35
|
};
|
|
43
|
-
export const clearToken = async (tokenId)=>{
|
|
36
|
+
export const clearToken = async (tokenId) => {
|
|
44
37
|
try {
|
|
45
38
|
await prisma.token.delete({
|
|
46
39
|
where: {
|
|
47
|
-
id: tokenId
|
|
48
|
-
}
|
|
40
|
+
id: tokenId,
|
|
41
|
+
},
|
|
49
42
|
});
|
|
50
|
-
}
|
|
51
|
-
|
|
43
|
+
}
|
|
44
|
+
catch (_e) {
|
|
45
|
+
// Nothing to for now
|
|
52
46
|
}
|
|
53
47
|
};
|
|
54
|
-
export const clearExpiredTokens = async ()=>{
|
|
48
|
+
export const clearExpiredTokens = async () => {
|
|
55
49
|
await prisma.token.deleteMany({
|
|
56
50
|
where: {
|
|
57
|
-
OR: [
|
|
58
|
-
|
|
59
|
-
expiresAt: {
|
|
60
|
-
lte: new Date()
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
invalid: true
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
}
|
|
51
|
+
OR: [{ expiresAt: { lte: new Date() } }, { invalid: true }],
|
|
52
|
+
},
|
|
68
53
|
});
|
|
69
54
|
};
|
package/dist/translations.js
CHANGED
|
@@ -4,15 +4,15 @@ export const translations = singleton('authTranslations', {
|
|
|
4
4
|
password: 'Password',
|
|
5
5
|
unauthenticated: 'Unauthenticated',
|
|
6
6
|
unauthenticatedDescription: 'You are not authenticated. Please log in to continue.',
|
|
7
|
-
wrongUsernameOrPassword: 'The username / password combination is invalid.'
|
|
7
|
+
wrongUsernameOrPassword: 'The username / password combination is invalid.',
|
|
8
8
|
});
|
|
9
|
-
export const setTranslations = (ts)=>{
|
|
10
|
-
for(const key in ts){
|
|
9
|
+
export const setTranslations = (ts) => {
|
|
10
|
+
for (const key in ts) {
|
|
11
11
|
// TODO
|
|
12
12
|
// @ts-expect-error
|
|
13
13
|
translations[key] = ts[key];
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
export const setTranslation = (key, value)=>{
|
|
16
|
+
export const setTranslation = (key, value) => {
|
|
17
17
|
translations[key] = value;
|
|
18
18
|
};
|
package/dist/use-auth.js
CHANGED
package/dist/use-session.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/auth",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.60",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
"@casl/ability": "^6.7.3",
|
|
76
76
|
"@casl/prisma": "^1.5.2",
|
|
77
77
|
"@driveflux/config": "3.0.8",
|
|
78
|
-
"@driveflux/db": "4.0.
|
|
79
|
-
"@driveflux/fetch": "8.0.
|
|
80
|
-
"@driveflux/problem": "6.0.
|
|
81
|
-
"@driveflux/reporter": "7.0.
|
|
82
|
-
"@driveflux/result": "6.0.
|
|
78
|
+
"@driveflux/db": "4.0.34",
|
|
79
|
+
"@driveflux/fetch": "8.0.1",
|
|
80
|
+
"@driveflux/problem": "6.0.1",
|
|
81
|
+
"@driveflux/reporter": "7.0.2",
|
|
82
|
+
"@driveflux/result": "6.0.1",
|
|
83
83
|
"@driveflux/singleton": "3.0.0",
|
|
84
84
|
"@driveflux/ui": "3.0.3",
|
|
85
85
|
"@driveflux/utils": "6.0.0",
|
|
86
|
-
"@driveflux/web-analytics": "3.0.
|
|
86
|
+
"@driveflux/web-analytics": "3.0.2",
|
|
87
87
|
"@types/cors": "^2.8.19",
|
|
88
88
|
"bcryptjs": "^3.0.2",
|
|
89
89
|
"change-case": "^5.4.4",
|