@driveflux/auth 4.0.63 → 4.0.64
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.d.ts.map +1 -1
- 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.d.ts.map +1 -1
- package/dist/authorization/roles/admin/head-of-engineering.js +6 -17
- package/dist/authorization/roles/admin/head-of-finance.d.ts.map +1 -1
- package/dist/authorization/roles/admin/head-of-finance.js +3 -8
- package/dist/authorization/roles/admin/head-of-human-resources.d.ts.map +1 -1
- package/dist/authorization/roles/admin/head-of-human-resources.js +5 -13
- package/dist/authorization/roles/admin/head-of-marketing.d.ts.map +1 -1
- package/dist/authorization/roles/admin/head-of-marketing.js +5 -17
- package/dist/authorization/roles/admin/head-of-operations.d.ts.map +1 -1
- package/dist/authorization/roles/admin/head-of-operations.js +3 -8
- package/dist/authorization/roles/admin/head-of-product.d.ts.map +1 -1
- package/dist/authorization/roles/admin/head-of-product.js +6 -17
- package/dist/authorization/roles/admin/head-of-sales.d.ts.map +1 -1
- 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/constants.d.ts +8 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- 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.d.ts +7 -7
- package/dist/server/next-auth.d.ts.map +1 -1
- 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 +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDocumentsFields, getPricingFields } from '../../utils.js';
|
|
2
|
-
export const defineRoleAbilitiesSalesExecutive = async (can, cannot)=>{
|
|
2
|
+
export const defineRoleAbilitiesSalesExecutive = async (can, cannot) => {
|
|
3
3
|
can('read', [
|
|
4
4
|
'Subscription',
|
|
5
5
|
'Cycle',
|
|
@@ -9,26 +9,16 @@ export const defineRoleAbilitiesSalesExecutive = async (can, cannot)=>{
|
|
|
9
9
|
'Host',
|
|
10
10
|
'Discount',
|
|
11
11
|
'PlatformConfig',
|
|
12
|
-
'PaymentLink'
|
|
12
|
+
'PaymentLink',
|
|
13
13
|
]);
|
|
14
|
-
can([
|
|
15
|
-
|
|
16
|
-
'update'
|
|
17
|
-
], [
|
|
18
|
-
'Invoice',
|
|
19
|
-
'Transaction',
|
|
20
|
-
'Refund'
|
|
21
|
-
]);
|
|
22
|
-
can([
|
|
23
|
-
'read',
|
|
24
|
-
'update'
|
|
25
|
-
], 'User');
|
|
14
|
+
can(['read', 'update'], ['Invoice', 'Transaction', 'Refund']);
|
|
15
|
+
can(['read', 'update'], 'User');
|
|
26
16
|
cannot('update', 'User', 'status');
|
|
27
17
|
cannot('update', 'User', [
|
|
28
18
|
...getDocumentsFields('identification'),
|
|
29
19
|
...getDocumentsFields('drivingHistory'),
|
|
30
20
|
...getDocumentsFields('financial'),
|
|
31
|
-
...getDocumentsFields('offerLetter')
|
|
21
|
+
...getDocumentsFields('offerLetter'),
|
|
32
22
|
]);
|
|
33
23
|
can('manage', 'Business');
|
|
34
24
|
can('manage', 'Inquiry');
|
|
@@ -39,23 +29,17 @@ export const defineRoleAbilitiesSalesExecutive = async (can, cannot)=>{
|
|
|
39
29
|
'endedAt',
|
|
40
30
|
'plan',
|
|
41
31
|
'mileagePackage',
|
|
42
|
-
'payerType'
|
|
32
|
+
'payerType',
|
|
43
33
|
]);
|
|
44
34
|
can('read', 'SubscriptionReservation');
|
|
45
|
-
cannot('update', 'Subscription', [
|
|
46
|
-
'status',
|
|
47
|
-
'started'
|
|
48
|
-
]);
|
|
35
|
+
cannot('update', 'Subscription', ['status', 'started']);
|
|
49
36
|
cannot('update', 'Vehicle', getPricingFields());
|
|
50
37
|
can('testPricingInput', 'Vehicle');
|
|
51
38
|
can('readPricingInput', 'Vehicle');
|
|
52
39
|
cannot('cancelInvoice', 'Invoice');
|
|
53
40
|
cannot('markInvoice', 'Invoice');
|
|
54
41
|
cannot('delete', 'Quotation');
|
|
55
|
-
cannot('read', [
|
|
56
|
-
'Vacancy',
|
|
57
|
-
'Applicant'
|
|
58
|
-
]);
|
|
42
|
+
cannot('read', ['Vacancy', 'Applicant']);
|
|
59
43
|
can('read', 'Activity');
|
|
60
44
|
can('read', 'ActivityTask');
|
|
61
45
|
};
|
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
export const defineRoleAbilitiesBusinessAdmin = async (can, user)=>{
|
|
1
|
+
export const defineRoleAbilitiesBusinessAdmin = async (can, user) => {
|
|
2
2
|
if (!user.businessId) {
|
|
3
3
|
return;
|
|
4
4
|
}
|
|
5
|
-
can([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
businessId: user.businessId
|
|
10
|
-
});
|
|
11
|
-
can('read', 'Subscription', {
|
|
12
|
-
businessId: user.businessId
|
|
13
|
-
});
|
|
14
|
-
can('update', 'Business', [
|
|
15
|
-
'phoneNumber',
|
|
16
|
-
'mobileNumber',
|
|
17
|
-
'addresses'
|
|
18
|
-
], {
|
|
19
|
-
id: user.businessId
|
|
20
|
-
});
|
|
21
|
-
can('read', 'Business', {
|
|
22
|
-
id: user.businessId
|
|
5
|
+
can(['read', 'update'], 'User', { businessId: user.businessId });
|
|
6
|
+
can('read', 'Subscription', { businessId: user.businessId });
|
|
7
|
+
can('update', 'Business', ['phoneNumber', 'mobileNumber', 'addresses'], {
|
|
8
|
+
id: user.businessId,
|
|
23
9
|
});
|
|
10
|
+
can('read', 'Business', { id: user.businessId });
|
|
24
11
|
can('create', 'Mandate');
|
|
25
12
|
};
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
export const defineRoleAbilitiesBusinessUser = async (can, user)=>{
|
|
1
|
+
export const defineRoleAbilitiesBusinessUser = async (can, user) => {
|
|
2
2
|
if (!user.businessId) {
|
|
3
3
|
return;
|
|
4
4
|
}
|
|
5
|
-
can([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
can('read', 'Subscription', {
|
|
11
|
-
businessId: user.businessId
|
|
12
|
-
});
|
|
13
|
-
can('update', 'Business', [
|
|
14
|
-
'phoneNumber',
|
|
15
|
-
'mobileNumber',
|
|
16
|
-
'addresses'
|
|
17
|
-
], {
|
|
18
|
-
id: user.businessId
|
|
19
|
-
});
|
|
20
|
-
can('read', 'Business', {
|
|
21
|
-
id: user.businessId
|
|
5
|
+
can(['read'], 'User', { businessId: user.businessId });
|
|
6
|
+
can('read', 'Subscription', { businessId: user.businessId });
|
|
7
|
+
can('update', 'Business', ['phoneNumber', 'mobileNumber', 'addresses'], {
|
|
8
|
+
id: user.businessId,
|
|
22
9
|
});
|
|
10
|
+
can('read', 'Business', { id: user.businessId });
|
|
23
11
|
can('create', 'Mandate');
|
|
24
12
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const defineRoleAbilitiesMember = async (can, user)=>{
|
|
1
|
+
export const defineRoleAbilitiesMember = async (can, user) => {
|
|
2
2
|
can('read', 'Cycle', [
|
|
3
3
|
'id',
|
|
4
4
|
'startDate',
|
|
@@ -6,23 +6,13 @@ export const defineRoleAbilitiesMember = async (can, user)=>{
|
|
|
6
6
|
'utilization.pricePerKm',
|
|
7
7
|
'utilization.paid',
|
|
8
8
|
'utilization.allowedMileage',
|
|
9
|
-
'utilization.mileage'
|
|
10
|
-
], {
|
|
11
|
-
|
|
12
|
-
userId: user.id
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
can('read', 'Vehicle', {
|
|
16
|
-
status: 'listed'
|
|
17
|
-
});
|
|
9
|
+
'utilization.mileage',
|
|
10
|
+
], { subscription: { userId: user.id } });
|
|
11
|
+
can('read', 'Vehicle', { status: 'listed' });
|
|
18
12
|
can('create', 'Business');
|
|
19
13
|
if (user.businessId) {
|
|
20
|
-
can('update', 'Business', {
|
|
21
|
-
id: user.businessId
|
|
22
|
-
});
|
|
14
|
+
can('update', 'Business', { id: user.businessId });
|
|
23
15
|
}
|
|
24
|
-
can('read', 'Subscription', {
|
|
25
|
-
userId: user.id
|
|
26
|
-
});
|
|
16
|
+
can('read', 'Subscription', { userId: user.id });
|
|
27
17
|
can('read', 'Coupon');
|
|
28
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
@@ -2,39 +2,32 @@ import { prisma } from '@driveflux/db';
|
|
|
2
2
|
import { makeProblem, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
3
3
|
import { Err, Ok } from '@driveflux/result';
|
|
4
4
|
import { defineAbilityFor } from './define.js';
|
|
5
|
-
export const updateUserPermissions = async (userId, newGroups)=>{
|
|
6
|
-
const user = typeof userId === 'string'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
export const updateUserPermissions = async (userId, newGroups) => {
|
|
6
|
+
const user = typeof userId === 'string'
|
|
7
|
+
? await prisma.user.findUnique({
|
|
8
|
+
where: {
|
|
9
|
+
id: userId,
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
: userId;
|
|
11
13
|
if (!user) {
|
|
12
14
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, 'User not found when trying to update the permissions'));
|
|
13
15
|
}
|
|
14
|
-
const groups = newGroups ? [
|
|
15
|
-
...newGroups
|
|
16
|
-
] : [
|
|
17
|
-
...user.groups
|
|
18
|
-
];
|
|
16
|
+
const groups = newGroups ? [...newGroups] : [...user.groups];
|
|
19
17
|
const ability = await defineAbilityFor({
|
|
20
18
|
...user,
|
|
21
|
-
groups
|
|
19
|
+
groups,
|
|
22
20
|
});
|
|
23
21
|
await prisma.user.update({
|
|
24
22
|
where: {
|
|
25
|
-
id: user.id
|
|
23
|
+
id: user.id,
|
|
26
24
|
},
|
|
27
25
|
data: {
|
|
28
|
-
groups: [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
permissions: ability.rules
|
|
32
|
-
}
|
|
26
|
+
groups: [...groups],
|
|
27
|
+
permissions: ability.rules,
|
|
28
|
+
},
|
|
33
29
|
});
|
|
34
30
|
user.groups = groups;
|
|
35
31
|
user.permissions = ability.rules;
|
|
36
|
-
return new Ok({
|
|
37
|
-
user,
|
|
38
|
-
ability
|
|
39
|
-
});
|
|
32
|
+
return new Ok({ user, ability });
|
|
40
33
|
};
|
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { subject } from '@casl/ability';
|
|
2
2
|
import { pascalCase } from 'change-case';
|
|
3
|
-
export const detectSubjectType = (subject)=>{
|
|
3
|
+
export const detectSubjectType = (subject) => {
|
|
4
4
|
if (!('object' in subject)) {
|
|
5
5
|
throw new Error(`Trying to get an object from model ${subject} that is not a real model`);
|
|
6
6
|
}
|
|
7
7
|
return pascalCase(subject.object);
|
|
8
8
|
};
|
|
9
9
|
const documents = {
|
|
10
|
-
identification: [
|
|
11
|
-
|
|
12
|
-
'passport',
|
|
13
|
-
'idFront',
|
|
14
|
-
'idBack',
|
|
15
|
-
'drivingLicense'
|
|
16
|
-
],
|
|
17
|
-
drivingHistory: [
|
|
18
|
-
'pdrm',
|
|
19
|
-
'jpj',
|
|
20
|
-
'bgs'
|
|
21
|
-
],
|
|
10
|
+
identification: ['visa', 'passport', 'idFront', 'idBack', 'drivingLicense'],
|
|
11
|
+
drivingHistory: ['pdrm', 'jpj', 'bgs'],
|
|
22
12
|
financial: [
|
|
23
13
|
'experianReport',
|
|
24
14
|
'bankStatement',
|
|
25
15
|
'bankStatement2',
|
|
26
16
|
'bankStatement3',
|
|
27
|
-
'epfStatement'
|
|
17
|
+
'epfStatement',
|
|
28
18
|
],
|
|
29
|
-
offerLetter: [
|
|
30
|
-
'offerLetter'
|
|
31
|
-
]
|
|
19
|
+
offerLetter: ['offerLetter'],
|
|
32
20
|
};
|
|
33
|
-
export const getDocumentsFields = (documentsGroup)=>documents[documentsGroup].map((d)
|
|
34
|
-
export const getPricingFields = ()=>{
|
|
21
|
+
export const getDocumentsFields = (documentsGroup) => documents[documentsGroup].map((d) => `documents.${d}`);
|
|
22
|
+
export const getPricingFields = () => {
|
|
35
23
|
return [
|
|
36
24
|
'pricing',
|
|
37
25
|
'basePrice',
|
|
@@ -39,17 +27,14 @@ export const getPricingFields = ()=>{
|
|
|
39
27
|
'basePricePlan12',
|
|
40
28
|
'basePricePlan24',
|
|
41
29
|
'basePricePlan36',
|
|
42
|
-
'basePricePlan60'
|
|
30
|
+
'basePricePlan60',
|
|
43
31
|
];
|
|
44
32
|
};
|
|
45
33
|
// we are creating a helper function to fake an object
|
|
46
|
-
export const s = (modelName, key = 'id')=>{
|
|
34
|
+
export const s = (modelName, key = 'id') => {
|
|
47
35
|
const objectName = getObjectName(modelName);
|
|
48
|
-
return subject(modelName, {
|
|
49
|
-
object: objectName,
|
|
50
|
-
[key]: 'XXXXXXXXX'
|
|
51
|
-
});
|
|
36
|
+
return subject(modelName, { object: objectName, [key]: 'XXXXXXXXX' });
|
|
52
37
|
};
|
|
53
|
-
const getObjectName = (modelName)=>{
|
|
38
|
+
const getObjectName = (modelName) => {
|
|
54
39
|
return modelName[0].toLowerCase() + modelName.slice(1);
|
|
55
40
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const AUTH_COOKIE_PREFIX
|
|
2
|
-
export declare const AUTH_COOKIE_ACCESSED_ADMIN
|
|
3
|
-
export declare const AUTH_COOKIE_SESSION_TOKEN
|
|
4
|
-
export declare const AUTH_COOKIE_CALLBACK_URL
|
|
5
|
-
export declare const AUTH_COOKIE_CSRF_TOKEN
|
|
6
|
-
export declare const AUTH_COOKIE_PKCE_CODE_VERIFIER
|
|
7
|
-
export declare const AUTH_COOKIE_STATE
|
|
8
|
-
export declare const AUTH_COOKIE_NONCE
|
|
1
|
+
export declare const AUTH_COOKIE_PREFIX: string;
|
|
2
|
+
export declare const AUTH_COOKIE_ACCESSED_ADMIN: string;
|
|
3
|
+
export declare const AUTH_COOKIE_SESSION_TOKEN: string;
|
|
4
|
+
export declare const AUTH_COOKIE_CALLBACK_URL: string;
|
|
5
|
+
export declare const AUTH_COOKIE_CSRF_TOKEN: string;
|
|
6
|
+
export declare const AUTH_COOKIE_PKCE_CODE_VERIFIER: string;
|
|
7
|
+
export declare const AUTH_COOKIE_STATE: string;
|
|
8
|
+
export declare const AUTH_COOKIE_NONCE: string;
|
|
9
9
|
export declare const PROBLEM_INVALID_LOGIN = "invalid_credentials";
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,QAEjB,CAAA;AAEd,eAAO,MAAM,0BAA0B,QAA6C,CAAA;AACpF,eAAO,MAAM,yBAAyB,QAAwC,CAAA;AAC9E,eAAO,MAAM,wBAAwB,QAAuC,CAAA;AAC5E,eAAO,MAAM,sBAAsB,QAAqC,CAAA;AACxE,eAAO,MAAM,8BAA8B,QAA6C,CAAA;AACxF,eAAO,MAAM,iBAAiB,QAAgC,CAAA;AAC9D,eAAO,MAAM,iBAAiB,QAAgC,CAAA;AAC9D,eAAO,MAAM,qBAAqB,wBAAwB,CAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const envSuffux = process.env.APP_ENV === 'production' ? '' : (process.env.APP_ENV ?? '');
|
|
2
|
+
export const AUTH_COOKIE_PREFIX = envSuffux
|
|
3
|
+
? `flux-auth.${envSuffux}`
|
|
4
|
+
: 'flux-auth';
|
|
2
5
|
export const AUTH_COOKIE_ACCESSED_ADMIN = `${AUTH_COOKIE_PREFIX}.has-accessed-admin`;
|
|
3
6
|
export const AUTH_COOKIE_SESSION_TOKEN = `${AUTH_COOKIE_PREFIX}.session-token`;
|
|
4
7
|
export const AUTH_COOKIE_CALLBACK_URL = `${AUTH_COOKIE_PREFIX}.callback-url`;
|
package/dist/context.js
CHANGED
|
@@ -2,15 +2,16 @@ import { createContext } from 'react';
|
|
|
2
2
|
const defaultContext = {
|
|
3
3
|
user: undefined,
|
|
4
4
|
isLoadingUser: false,
|
|
5
|
-
signIn: async ()=>Promise.resolve(undefined),
|
|
6
|
-
refresh: async ()=>Promise.resolve(undefined),
|
|
5
|
+
signIn: async () => Promise.resolve(undefined),
|
|
6
|
+
refresh: async () => Promise.resolve(undefined),
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
*
|
|
9
|
+
* @deprecated There's no need for access token anymore, we use cookies
|
|
10
|
+
*/
|
|
11
|
+
getAccessToken: async () => Promise.resolve(undefined),
|
|
11
12
|
// TODO
|
|
12
13
|
// eslint-disable-next-line @typescript-eslint/no-empty-function -- initial state
|
|
13
|
-
logout: ()=>{},
|
|
14
|
-
status: 'loading'
|
|
14
|
+
logout: () => { },
|
|
15
|
+
status: 'loading',
|
|
15
16
|
};
|
|
16
|
-
export const AuthContext =
|
|
17
|
+
export const AuthContext = createContext(defaultContext);
|
package/dist/default.js
CHANGED
|
@@ -5,29 +5,25 @@ import bcrypt from 'bcryptjs';
|
|
|
5
5
|
import { PROBLEM_INVALID_LOGIN } from '../constants.js';
|
|
6
6
|
import { translations } from '../translations.js';
|
|
7
7
|
import { verifyToken } from './verfiy-token.js';
|
|
8
|
-
export const authenticateUser = async ({ login, password })=>{
|
|
8
|
+
export const authenticateUser = async ({ login, password, }) => {
|
|
9
9
|
const isEmail = login.includes('@');
|
|
10
10
|
// Check if the user exists
|
|
11
11
|
const user = await prisma.user.findFirst({
|
|
12
12
|
where: {
|
|
13
|
-
...isEmail
|
|
14
|
-
email: login.toLowerCase().trim()
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
13
|
+
...(isEmail
|
|
14
|
+
? { email: login.toLowerCase().trim() }
|
|
15
|
+
: { phoneNumber: login.replace(/[\s-]/g, '') }),
|
|
16
|
+
},
|
|
19
17
|
});
|
|
20
18
|
if (!user) {
|
|
21
19
|
return new Err(makeProblem(PROBLEM_INVALID_LOGIN, translations.wrongUsernameOrPassword));
|
|
22
20
|
}
|
|
23
21
|
// Check the user's password
|
|
24
|
-
if (isEmail && !await bcrypt.compare(password, user.password)) {
|
|
22
|
+
if (isEmail && !(await bcrypt.compare(password, user.password))) {
|
|
25
23
|
return new Err(makeProblem(PROBLEM_INVALID_LOGIN, 'The email / password combination is invalid.'));
|
|
26
24
|
}
|
|
27
25
|
if (!isEmail) {
|
|
28
|
-
const tokenResult = await verifyToken(password, {
|
|
29
|
-
scope: 'verify-phone'
|
|
30
|
-
});
|
|
26
|
+
const tokenResult = await verifyToken(password, { scope: 'verify-phone' });
|
|
31
27
|
if (!tokenResult.ok) {
|
|
32
28
|
return new Err(makeProblem(PROBLEM_INVALID_LOGIN, 'The OTP is invalid.'));
|
|
33
29
|
}
|
package/dist/server/cors.js
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
import { config } from '@driveflux/config/backend';
|
|
2
2
|
import Cors from 'cors';
|
|
3
3
|
const corsOptions = {
|
|
4
|
-
origin: (origin, callback)=>{
|
|
5
|
-
const allowedOrigins = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (config.appEnv === 'development' || origin && allowedOrigins.includes(origin)) {
|
|
4
|
+
origin: (origin, callback) => {
|
|
5
|
+
const allowedOrigins = [config.appUrl];
|
|
6
|
+
if (config.appEnv === 'development' ||
|
|
7
|
+
(origin && allowedOrigins.includes(origin))) {
|
|
9
8
|
callback(null, true);
|
|
10
|
-
}
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
11
|
callback(new Error('CORS not allowed'));
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
allowedHeaders: [
|
|
15
|
-
'content-type',
|
|
16
|
-
'x-correlation-id',
|
|
17
|
-
'authorization'
|
|
18
|
-
],
|
|
14
|
+
allowedHeaders: ['content-type', 'x-correlation-id', 'authorization'],
|
|
19
15
|
exposedHeaders: '*',
|
|
20
|
-
methods: [
|
|
21
|
-
|
|
22
|
-
'HEAD',
|
|
23
|
-
'PUT',
|
|
24
|
-
'PATCH',
|
|
25
|
-
'POST',
|
|
26
|
-
'DELETE'
|
|
27
|
-
],
|
|
28
|
-
credentials: true
|
|
16
|
+
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
|
|
17
|
+
credentials: true,
|
|
29
18
|
};
|
|
30
19
|
// Initializing the cors middleware
|
|
31
20
|
// I don't have time to debug cors now, I've got a million things to do.
|
|
32
21
|
// TODO Implement this properly please
|
|
33
22
|
const corsHandler = config.appEnv === 'development' ? Cors(corsOptions) : Cors();
|
|
34
|
-
export const cors = (req, res)=>{
|
|
35
|
-
return new Promise((resolve, reject)=>{
|
|
36
|
-
corsHandler(req, res, (result)=>{
|
|
23
|
+
export const cors = (req, res) => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
corsHandler(req, res, (result) => {
|
|
37
26
|
if (result instanceof Error) {
|
|
38
27
|
return reject(result);
|
|
39
28
|
}
|
|
@@ -37,7 +37,7 @@ export declare const authOptions: {
|
|
|
37
37
|
};
|
|
38
38
|
credentials?: Record<string, import("next-auth/providers/credentials").CredentialInput>;
|
|
39
39
|
}) => Promise<boolean>;
|
|
40
|
-
readonly session: ({ session, user, trigger
|
|
40
|
+
readonly session: ({ session, user, trigger }: {
|
|
41
41
|
session: import("next-auth").Session;
|
|
42
42
|
token: import("next-auth/jwt").JWT;
|
|
43
43
|
user: import("next-auth/adapters").AdapterUser;
|
|
@@ -358,7 +358,7 @@ export declare const authOptions: {
|
|
|
358
358
|
};
|
|
359
359
|
readonly cookies: {
|
|
360
360
|
readonly sessionToken: {
|
|
361
|
-
readonly name:
|
|
361
|
+
readonly name: string;
|
|
362
362
|
readonly options: {
|
|
363
363
|
readonly httpOnly: true;
|
|
364
364
|
readonly sameSite: "lax";
|
|
@@ -368,7 +368,7 @@ export declare const authOptions: {
|
|
|
368
368
|
};
|
|
369
369
|
};
|
|
370
370
|
readonly callbackUrl: {
|
|
371
|
-
readonly name:
|
|
371
|
+
readonly name: string;
|
|
372
372
|
readonly options: {
|
|
373
373
|
readonly httpOnly: true;
|
|
374
374
|
readonly sameSite: "lax";
|
|
@@ -377,7 +377,7 @@ export declare const authOptions: {
|
|
|
377
377
|
};
|
|
378
378
|
};
|
|
379
379
|
readonly csrfToken: {
|
|
380
|
-
readonly name:
|
|
380
|
+
readonly name: string;
|
|
381
381
|
readonly options: {
|
|
382
382
|
readonly httpOnly: true;
|
|
383
383
|
readonly sameSite: "lax";
|
|
@@ -386,7 +386,7 @@ export declare const authOptions: {
|
|
|
386
386
|
};
|
|
387
387
|
};
|
|
388
388
|
readonly pkceCodeVerifier: {
|
|
389
|
-
readonly name:
|
|
389
|
+
readonly name: string;
|
|
390
390
|
readonly options: {
|
|
391
391
|
readonly httpOnly: true;
|
|
392
392
|
readonly sameSite: "lax";
|
|
@@ -396,7 +396,7 @@ export declare const authOptions: {
|
|
|
396
396
|
};
|
|
397
397
|
};
|
|
398
398
|
readonly state: {
|
|
399
|
-
readonly name:
|
|
399
|
+
readonly name: string;
|
|
400
400
|
readonly options: {
|
|
401
401
|
readonly httpOnly: true;
|
|
402
402
|
readonly sameSite: "lax";
|
|
@@ -406,7 +406,7 @@ export declare const authOptions: {
|
|
|
406
406
|
};
|
|
407
407
|
};
|
|
408
408
|
readonly nonce: {
|
|
409
|
-
readonly name:
|
|
409
|
+
readonly name: string;
|
|
410
410
|
readonly options: {
|
|
411
411
|
readonly httpOnly: true;
|
|
412
412
|
readonly sameSite: "lax";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-auth.d.ts","sourceRoot":"","sources":["../../src/server/next-auth.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,CAAA;AAK5B,OAAO,KAAK,EAAE,IAAI,IAAI,WAAW,EAAmB,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"next-auth.d.ts","sourceRoot":"","sources":["../../src/server/next-auth.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,CAAA;AAK5B,OAAO,KAAK,EAAE,IAAI,IAAI,WAAW,EAAmB,MAAM,WAAW,CAAA;AA6BrE,eAAO,MAAM,oBAAoB,GAChC,MAAM,WAAW,KACf,OAAO,CAAC,MAAM,CAehB,CAAA;AAED,eAAO,MAAM,qBAAqB;;;;;;;;;;;;2BAQlB,MAAM,CAAC,UAAU,GAAG,OAAO,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3D,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAQ/B,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;mCA+S24E,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADh4E,CAAA"}
|