@skroz/profile-api 1.0.13 → 1.0.15
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/dto/{RegisterInput.d.ts → AuthInput.d.ts} +6 -2
- package/dist/dto/{RegisterInput.js → AuthInput.js} +13 -9
- package/dist/dto/SendTokenPayload.d.ts +1 -1
- package/dist/dto/SendTokenPayload.js +1 -1
- package/dist/dto/index.d.ts +1 -2
- package/dist/dto/index.js +6 -9
- package/dist/resolvers/AuthResolver.d.ts +1 -1
- package/dist/resolvers/AuthResolver.js +11 -11
- package/dist/resolvers/ProfileResolver.d.ts +2 -2
- package/dist/resolvers/ProfileResolver.js +4 -4
- package/package.json +3 -3
- package/src/dto/{RegisterInput.ts → AuthInput.ts} +15 -7
- package/src/dto/SendTokenPayload.ts +2 -2
- package/src/dto/index.ts +6 -2
- package/src/resolvers/AuthResolver.ts +14 -20
- package/src/resolvers/ProfileResolver.ts +8 -6
- package/dist/dto/LoginInput.d.ts +0 -12
- package/dist/dto/LoginInput.js +0 -64
- package/src/dto/LoginInput.ts +0 -20
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import PasswordInput from './PasswordInput';
|
|
2
|
-
export default class
|
|
2
|
+
export default class AuthInput extends PasswordInput {
|
|
3
3
|
email: string;
|
|
4
4
|
isUserAgreementAgree?: boolean;
|
|
5
5
|
isPrivacyPolicyAgree?: boolean;
|
|
6
6
|
}
|
|
7
|
+
export declare const loginValidators: {
|
|
8
|
+
email: import("@os-team/graphql-validators").Validator[];
|
|
9
|
+
password: import("@os-team/graphql-validators").Validator[];
|
|
10
|
+
};
|
|
7
11
|
export declare const registerValidators: {
|
|
8
12
|
password: import("@os-team/graphql-validators").Validator[];
|
|
9
13
|
email: import("@os-team/graphql-validators").Validator[];
|
|
10
14
|
isUserAgreementAgree: import("@os-team/graphql-validators").Validator[];
|
|
11
15
|
isPrivacyPolicyAgree: import("@os-team/graphql-validators").Validator[];
|
|
12
16
|
};
|
|
13
|
-
export declare const
|
|
17
|
+
export declare const authTransformers: {
|
|
14
18
|
password: import("@os-team/graphql-transformers").Transformer[];
|
|
15
19
|
email: import("@os-team/graphql-transformers").Transformer[];
|
|
16
20
|
};
|
|
@@ -45,29 +45,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.
|
|
48
|
+
exports.authTransformers = exports.registerValidators = exports.loginValidators = void 0;
|
|
49
49
|
const type_graphql_1 = require("type-graphql");
|
|
50
50
|
const graphql_validators_1 = require("@os-team/graphql-validators");
|
|
51
51
|
const graphql_transformers_1 = require("@os-team/graphql-transformers");
|
|
52
52
|
const PasswordInput_1 = __importStar(require("./PasswordInput"));
|
|
53
53
|
const isTrue_1 = __importDefault(require("../validators/isTrue"));
|
|
54
|
-
let
|
|
54
|
+
let AuthInput = class AuthInput extends PasswordInput_1.default {
|
|
55
55
|
};
|
|
56
56
|
__decorate([
|
|
57
57
|
(0, type_graphql_1.Field)(),
|
|
58
58
|
__metadata("design:type", String)
|
|
59
|
-
],
|
|
59
|
+
], AuthInput.prototype, "email", void 0);
|
|
60
60
|
__decorate([
|
|
61
61
|
(0, type_graphql_1.Field)(() => Boolean, { nullable: true }),
|
|
62
62
|
__metadata("design:type", Boolean)
|
|
63
|
-
],
|
|
63
|
+
], AuthInput.prototype, "isUserAgreementAgree", void 0);
|
|
64
64
|
__decorate([
|
|
65
65
|
(0, type_graphql_1.Field)(() => Boolean, { nullable: true }),
|
|
66
66
|
__metadata("design:type", Boolean)
|
|
67
|
-
],
|
|
68
|
-
|
|
67
|
+
], AuthInput.prototype, "isPrivacyPolicyAgree", void 0);
|
|
68
|
+
AuthInput = __decorate([
|
|
69
69
|
(0, type_graphql_1.InputType)()
|
|
70
|
-
],
|
|
71
|
-
exports.default =
|
|
70
|
+
], AuthInput);
|
|
71
|
+
exports.default = AuthInput;
|
|
72
|
+
exports.loginValidators = {
|
|
73
|
+
email: [graphql_validators_1.isEmail],
|
|
74
|
+
password: [graphql_validators_1.isNotEmpty],
|
|
75
|
+
};
|
|
72
76
|
exports.registerValidators = Object.assign({ email: [graphql_validators_1.isEmail], isUserAgreementAgree: [isTrue_1.default], isPrivacyPolicyAgree: [isTrue_1.default] }, PasswordInput_1.passwordValidators);
|
|
73
|
-
exports.
|
|
77
|
+
exports.authTransformers = Object.assign({ email: [graphql_transformers_1.trim, graphql_transformers_1.toLowerCase] }, PasswordInput_1.passwordTransformers);
|
|
@@ -17,7 +17,7 @@ __decorate([
|
|
|
17
17
|
__metadata("design:type", Boolean)
|
|
18
18
|
], SendTokenPayload.prototype, "codeIsSent", void 0);
|
|
19
19
|
__decorate([
|
|
20
|
-
(0, type_graphql_1.Field)(() => Number
|
|
20
|
+
(0, type_graphql_1.Field)(() => Number),
|
|
21
21
|
__metadata("design:type", Number)
|
|
22
22
|
], SendTokenPayload.prototype, "limitExpiresAt", void 0);
|
|
23
23
|
SendTokenPayload = __decorate([
|
package/dist/dto/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { default as PasswordInput, passwordTransformers, passwordValidators } from './PasswordInput';
|
|
2
|
-
export { default as
|
|
3
|
-
export { default as LoginInput, loginTransformers, loginValidators } from './LoginInput';
|
|
2
|
+
export { default as AuthInput, registerValidators, loginValidators, authTransformers, } from './AuthInput';
|
|
4
3
|
export { default as ForgotPasswordInput, forgotPasswordTransformers, forgotPasswordValidators } from './ForgotPasswordInput';
|
|
5
4
|
export { default as ConfirmEmailInput, confirmEmailValidators } from './ConfirmEmailInput';
|
|
6
5
|
export { default as StatusPayload } from './StatusPayload';
|
package/dist/dto/index.js
CHANGED
|
@@ -3,19 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.recoverPasswordValidators = exports.recoverPasswordTransformers = exports.RecoverPasswordInput = exports.sendTokenValidators = exports.sendTokenTransformers = exports.SendTokenInput = exports.updateProfileValidators = exports.updateProfileTransformers = exports.UpdateProfileInput = exports.updateEmailValidators = exports.updateEmailTransformers = exports.UpdateEmailInput = exports.updatePasswordValidators = exports.updatePasswordTransformers = exports.UpdatePasswordInput = exports.SendTokenPayload = exports.StatusPayload = exports.confirmEmailValidators = exports.ConfirmEmailInput = exports.forgotPasswordValidators = exports.forgotPasswordTransformers = exports.ForgotPasswordInput = exports.
|
|
6
|
+
exports.recoverPasswordValidators = exports.recoverPasswordTransformers = exports.RecoverPasswordInput = exports.sendTokenValidators = exports.sendTokenTransformers = exports.SendTokenInput = exports.updateProfileValidators = exports.updateProfileTransformers = exports.UpdateProfileInput = exports.updateEmailValidators = exports.updateEmailTransformers = exports.UpdateEmailInput = exports.updatePasswordValidators = exports.updatePasswordTransformers = exports.UpdatePasswordInput = exports.SendTokenPayload = exports.StatusPayload = exports.confirmEmailValidators = exports.ConfirmEmailInput = exports.forgotPasswordValidators = exports.forgotPasswordTransformers = exports.ForgotPasswordInput = exports.authTransformers = exports.loginValidators = exports.registerValidators = exports.AuthInput = exports.passwordValidators = exports.passwordTransformers = exports.PasswordInput = void 0;
|
|
7
7
|
var PasswordInput_1 = require("./PasswordInput");
|
|
8
8
|
Object.defineProperty(exports, "PasswordInput", { enumerable: true, get: function () { return __importDefault(PasswordInput_1).default; } });
|
|
9
9
|
Object.defineProperty(exports, "passwordTransformers", { enumerable: true, get: function () { return PasswordInput_1.passwordTransformers; } });
|
|
10
10
|
Object.defineProperty(exports, "passwordValidators", { enumerable: true, get: function () { return PasswordInput_1.passwordValidators; } });
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
Object.defineProperty(exports, "
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(exports, "LoginInput", { enumerable: true, get: function () { return __importDefault(LoginInput_1).default; } });
|
|
17
|
-
Object.defineProperty(exports, "loginTransformers", { enumerable: true, get: function () { return LoginInput_1.loginTransformers; } });
|
|
18
|
-
Object.defineProperty(exports, "loginValidators", { enumerable: true, get: function () { return LoginInput_1.loginValidators; } });
|
|
11
|
+
var AuthInput_1 = require("./AuthInput");
|
|
12
|
+
Object.defineProperty(exports, "AuthInput", { enumerable: true, get: function () { return __importDefault(AuthInput_1).default; } });
|
|
13
|
+
Object.defineProperty(exports, "registerValidators", { enumerable: true, get: function () { return AuthInput_1.registerValidators; } });
|
|
14
|
+
Object.defineProperty(exports, "loginValidators", { enumerable: true, get: function () { return AuthInput_1.loginValidators; } });
|
|
15
|
+
Object.defineProperty(exports, "authTransformers", { enumerable: true, get: function () { return AuthInput_1.authTransformers; } });
|
|
19
16
|
var ForgotPasswordInput_1 = require("./ForgotPasswordInput");
|
|
20
17
|
Object.defineProperty(exports, "ForgotPasswordInput", { enumerable: true, get: function () { return __importDefault(ForgotPasswordInput_1).default; } });
|
|
21
18
|
Object.defineProperty(exports, "forgotPasswordTransformers", { enumerable: true, get: function () { return ForgotPasswordInput_1.forgotPasswordTransformers; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProfileAuthService } from '../services/ProfileAuthService';
|
|
2
2
|
import { ProfileContext } from '../types';
|
|
3
3
|
export interface AuthResolverDependencies<TContext extends ProfileContext = ProfileContext> {
|
|
4
|
-
authService: ProfileAuthService | (() => ProfileAuthService);
|
|
4
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
5
5
|
userType: any;
|
|
6
6
|
onUserCreated?: (user: any, ctx: TContext) => Promise<void>;
|
|
7
7
|
onLogin?: (user: any, ctx: TContext) => Promise<void>;
|
|
@@ -30,16 +30,16 @@ const ProfileAuthService_1 = require("../services/ProfileAuthService");
|
|
|
30
30
|
const dto_1 = require("../dto");
|
|
31
31
|
function createAuthResolver(deps) {
|
|
32
32
|
const { authService, onUserCreated, onLogin, onLogout, onEmailConfirmed, onPasswordRecovered, logTelegramBot, userType, } = deps;
|
|
33
|
-
const getAuthService = () => {
|
|
33
|
+
const getAuthService = (ctx) => {
|
|
34
34
|
if (typeof authService === 'function')
|
|
35
|
-
return authService();
|
|
35
|
+
return authService(ctx);
|
|
36
36
|
return authService;
|
|
37
37
|
};
|
|
38
38
|
let AuthResolver = class AuthResolver {
|
|
39
39
|
register(input, ctx) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const { t } = ctx;
|
|
42
|
-
const service = getAuthService();
|
|
42
|
+
const service = getAuthService(ctx);
|
|
43
43
|
if (yield service.db.isEmailTaken(input.email)) {
|
|
44
44
|
throw new Error(t('validation:auth.emailExists'));
|
|
45
45
|
}
|
|
@@ -65,7 +65,7 @@ function createAuthResolver(deps) {
|
|
|
65
65
|
login(input, ctx) {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
67
|
const { t } = ctx;
|
|
68
|
-
const service = getAuthService();
|
|
68
|
+
const service = getAuthService(ctx);
|
|
69
69
|
const user = yield service.db.findUserByEmail(input.email);
|
|
70
70
|
if (!user)
|
|
71
71
|
throw new Error(t('validation:user.notFound'));
|
|
@@ -102,7 +102,7 @@ function createAuthResolver(deps) {
|
|
|
102
102
|
}
|
|
103
103
|
confirmEmail(input, ctx) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const service = getAuthService();
|
|
105
|
+
const service = getAuthService(ctx);
|
|
106
106
|
const user = yield service.getUserByToken(ProfileAuthService_1.AUTH_TOKEN_REDIS_PREFIX, input.token);
|
|
107
107
|
if (!user)
|
|
108
108
|
throw new Error(ctx.t('validation:error.wrongCode'));
|
|
@@ -126,7 +126,7 @@ function createAuthResolver(deps) {
|
|
|
126
126
|
sendToken(input, ctx) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
128
|
const { t } = ctx;
|
|
129
|
-
const service = getAuthService();
|
|
129
|
+
const service = getAuthService(ctx);
|
|
130
130
|
const user = yield service.db.findUserByEmail(input.email);
|
|
131
131
|
if (!user)
|
|
132
132
|
throw new Error(t('validation:user.notFound'));
|
|
@@ -142,7 +142,7 @@ function createAuthResolver(deps) {
|
|
|
142
142
|
}
|
|
143
143
|
recoverPassword(input, ctx) {
|
|
144
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const service = getAuthService();
|
|
145
|
+
const service = getAuthService(ctx);
|
|
146
146
|
const user = yield service.getUserByToken(ProfileAuthService_1.AUTH_TOKEN_REDIS_PREFIX, input.token);
|
|
147
147
|
if (!user)
|
|
148
148
|
throw new Error(ctx.t('validation:error.wrongCode'));
|
|
@@ -166,23 +166,23 @@ function createAuthResolver(deps) {
|
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
__decorate([
|
|
169
|
-
(0, graphql_transformers_1.TransformArgs)(dto_1.
|
|
169
|
+
(0, graphql_transformers_1.TransformArgs)(dto_1.authTransformers, { arg: 'input' }),
|
|
170
170
|
(0, graphql_validators_1.ValidateArgs)(dto_1.registerValidators, { arg: 'input', tKey: 'register' }),
|
|
171
171
|
(0, type_graphql_1.Mutation)(() => userType),
|
|
172
172
|
__param(0, (0, type_graphql_1.Arg)('input')),
|
|
173
173
|
__param(1, (0, type_graphql_1.Ctx)()),
|
|
174
174
|
__metadata("design:type", Function),
|
|
175
|
-
__metadata("design:paramtypes", [dto_1.
|
|
175
|
+
__metadata("design:paramtypes", [dto_1.AuthInput, Object]),
|
|
176
176
|
__metadata("design:returntype", Promise)
|
|
177
177
|
], AuthResolver.prototype, "register", null);
|
|
178
178
|
__decorate([
|
|
179
|
-
(0, graphql_transformers_1.TransformArgs)(dto_1.
|
|
179
|
+
(0, graphql_transformers_1.TransformArgs)(dto_1.authTransformers, { arg: 'input' }),
|
|
180
180
|
(0, graphql_validators_1.ValidateArgs)(dto_1.loginValidators, { arg: 'input', tKey: 'register' }),
|
|
181
181
|
(0, type_graphql_1.Mutation)(() => graphql_utils_1.StatusPayload),
|
|
182
182
|
__param(0, (0, type_graphql_1.Arg)('input')),
|
|
183
183
|
__param(1, (0, type_graphql_1.Ctx)()),
|
|
184
184
|
__metadata("design:type", Function),
|
|
185
|
-
__metadata("design:paramtypes", [dto_1.
|
|
185
|
+
__metadata("design:paramtypes", [dto_1.AuthInput, Object]),
|
|
186
186
|
__metadata("design:returntype", Promise)
|
|
187
187
|
], AuthResolver.prototype, "login", null);
|
|
188
188
|
__decorate([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProfileAuthService } from '../services/ProfileAuthService';
|
|
2
2
|
import { ProfileContext } from '../types';
|
|
3
|
-
export interface ProfileResolverDependencies {
|
|
4
|
-
authService: ProfileAuthService | (() => ProfileAuthService);
|
|
3
|
+
export interface ProfileResolverDependencies<TContext extends ProfileContext = ProfileContext> {
|
|
4
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
5
5
|
userType: any;
|
|
6
6
|
}
|
|
7
7
|
export declare function createProfileResolver<TContext extends ProfileContext = ProfileContext>(deps: ProfileResolverDependencies): any;
|
|
@@ -29,9 +29,9 @@ const graphql_validators_1 = require("@os-team/graphql-validators");
|
|
|
29
29
|
const dto_1 = require("../dto");
|
|
30
30
|
function createProfileResolver(deps) {
|
|
31
31
|
const { authService, userType } = deps;
|
|
32
|
-
const getAuthService = () => {
|
|
32
|
+
const getAuthService = (ctx) => {
|
|
33
33
|
if (typeof authService === 'function')
|
|
34
|
-
return authService();
|
|
34
|
+
return authService(ctx);
|
|
35
35
|
return authService;
|
|
36
36
|
};
|
|
37
37
|
let ProfileResolver = class ProfileResolver {
|
|
@@ -40,7 +40,7 @@ function createProfileResolver(deps) {
|
|
|
40
40
|
const { user, t } = ctx;
|
|
41
41
|
if (!user)
|
|
42
42
|
throw new type_graphql_1.UnauthorizedError();
|
|
43
|
-
const service = getAuthService();
|
|
43
|
+
const service = getAuthService(ctx);
|
|
44
44
|
if (yield service.db.isEmailTaken(input.email, user.id)) {
|
|
45
45
|
throw new Error(t('validation:updateEmail.emailExists'));
|
|
46
46
|
}
|
|
@@ -55,7 +55,7 @@ function createProfileResolver(deps) {
|
|
|
55
55
|
const { user, t } = ctx;
|
|
56
56
|
if (!user)
|
|
57
57
|
throw new type_graphql_1.UnauthorizedError();
|
|
58
|
-
const service = getAuthService();
|
|
58
|
+
const service = getAuthService(ctx);
|
|
59
59
|
const isOldPasswordOk = yield service.verifyPassword(user.password, input.oldPassword);
|
|
60
60
|
if (!isOldPasswordOk)
|
|
61
61
|
throw new Error(t('validation:updatePassword.wrongPassword'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skroz/profile-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "git@gitlab.com:skroz/libs/utils.git",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"!**/*.test.ts"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"clean": "
|
|
14
|
+
"clean": "rm -rf dist",
|
|
15
15
|
"build": "yarn clean && tsc --outDir dist && cp -R src/email-templates dist/email-templates",
|
|
16
16
|
"ncu": "ncu -u"
|
|
17
17
|
},
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"type-graphql": "^1.1.1",
|
|
44
44
|
"typeorm": "^0.2.45"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3c39e01e47b436cbea6d9ab68dd8daada0c91862"
|
|
47
47
|
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import { Field, InputType } from 'type-graphql';
|
|
2
|
-
import { isEmail } from '@os-team/graphql-validators';
|
|
2
|
+
import { isEmail, isNotEmpty } from '@os-team/graphql-validators';
|
|
3
3
|
import { toLowerCase, trim } from '@os-team/graphql-transformers';
|
|
4
|
-
import PasswordInput, {
|
|
4
|
+
import PasswordInput, {
|
|
5
|
+
passwordTransformers,
|
|
6
|
+
passwordValidators,
|
|
7
|
+
} from './PasswordInput';
|
|
5
8
|
import isTrue from '../validators/isTrue';
|
|
6
9
|
|
|
7
10
|
@InputType()
|
|
8
|
-
export default class
|
|
11
|
+
export default class AuthInput extends PasswordInput {
|
|
9
12
|
@Field()
|
|
10
|
-
email!: string;
|
|
13
|
+
public email!: string;
|
|
11
14
|
|
|
12
15
|
@Field(() => Boolean, { nullable: true })
|
|
13
|
-
isUserAgreementAgree?: boolean;
|
|
16
|
+
public isUserAgreementAgree?: boolean;
|
|
14
17
|
|
|
15
18
|
@Field(() => Boolean, { nullable: true })
|
|
16
|
-
isPrivacyPolicyAgree?: boolean;
|
|
19
|
+
public isPrivacyPolicyAgree?: boolean;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
export const loginValidators = {
|
|
23
|
+
email: [isEmail],
|
|
24
|
+
password: [isNotEmpty],
|
|
25
|
+
};
|
|
26
|
+
|
|
19
27
|
export const registerValidators = {
|
|
20
28
|
email: [isEmail],
|
|
21
29
|
isUserAgreementAgree: [isTrue],
|
|
@@ -23,7 +31,7 @@ export const registerValidators = {
|
|
|
23
31
|
...passwordValidators,
|
|
24
32
|
};
|
|
25
33
|
|
|
26
|
-
export const
|
|
34
|
+
export const authTransformers = {
|
|
27
35
|
email: [trim, toLowerCase],
|
|
28
36
|
...passwordTransformers,
|
|
29
37
|
};
|
package/src/dto/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { default as PasswordInput, passwordTransformers, passwordValidators } from './PasswordInput';
|
|
2
|
-
export {
|
|
3
|
-
|
|
2
|
+
export {
|
|
3
|
+
default as AuthInput,
|
|
4
|
+
registerValidators,
|
|
5
|
+
loginValidators,
|
|
6
|
+
authTransformers,
|
|
7
|
+
} from './AuthInput';
|
|
4
8
|
export { default as ForgotPasswordInput, forgotPasswordTransformers, forgotPasswordValidators } from './ForgotPasswordInput';
|
|
5
9
|
export { default as ConfirmEmailInput, confirmEmailValidators } from './ConfirmEmailInput';
|
|
6
10
|
export { default as StatusPayload } from './StatusPayload';
|
|
@@ -8,16 +8,11 @@ import {
|
|
|
8
8
|
} from '../services/ProfileAuthService';
|
|
9
9
|
import { ProfileContext } from '../types';
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
registerTransformers,
|
|
11
|
+
AuthInput,
|
|
13
12
|
registerValidators,
|
|
14
|
-
LoginInput,
|
|
15
|
-
loginTransformers,
|
|
16
13
|
loginValidators,
|
|
14
|
+
authTransformers,
|
|
17
15
|
ConfirmEmailInput,
|
|
18
|
-
ForgotPasswordInput,
|
|
19
|
-
forgotPasswordTransformers,
|
|
20
|
-
forgotPasswordValidators,
|
|
21
16
|
RecoverPasswordInput,
|
|
22
17
|
recoverPasswordTransformers,
|
|
23
18
|
recoverPasswordValidators,
|
|
@@ -31,7 +26,7 @@ import {
|
|
|
31
26
|
export interface AuthResolverDependencies<
|
|
32
27
|
TContext extends ProfileContext = ProfileContext
|
|
33
28
|
> {
|
|
34
|
-
authService: ProfileAuthService | (() => ProfileAuthService);
|
|
29
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
35
30
|
userType: any;
|
|
36
31
|
onUserCreated?: (user: any, ctx: TContext) => Promise<void>;
|
|
37
32
|
onLogin?: (user: any, ctx: TContext) => Promise<void>;
|
|
@@ -55,19 +50,19 @@ export function createAuthResolver<
|
|
|
55
50
|
userType,
|
|
56
51
|
} = deps;
|
|
57
52
|
|
|
58
|
-
const getAuthService = (): ProfileAuthService => {
|
|
59
|
-
if (typeof authService === 'function') return authService();
|
|
53
|
+
const getAuthService = (ctx: TContext): ProfileAuthService => {
|
|
54
|
+
if (typeof authService === 'function') return authService(ctx);
|
|
60
55
|
return authService;
|
|
61
56
|
};
|
|
62
57
|
|
|
63
58
|
@Resolver(() => userType)
|
|
64
59
|
class AuthResolver {
|
|
65
|
-
@TransformArgs(
|
|
60
|
+
@TransformArgs(authTransformers, { arg: 'input' })
|
|
66
61
|
@ValidateArgs(registerValidators, { arg: 'input', tKey: 'register' })
|
|
67
62
|
@Mutation(() => userType)
|
|
68
|
-
async register(@Arg('input') input:
|
|
63
|
+
async register(@Arg('input') input: AuthInput, @Ctx() ctx: TContext) {
|
|
69
64
|
const { t } = ctx;
|
|
70
|
-
const service = getAuthService();
|
|
65
|
+
const service = getAuthService(ctx);
|
|
71
66
|
if (await service.db.isEmailTaken(input.email)) {
|
|
72
67
|
throw new Error(t('validation:auth.emailExists'));
|
|
73
68
|
}
|
|
@@ -93,12 +88,12 @@ export function createAuthResolver<
|
|
|
93
88
|
return user;
|
|
94
89
|
}
|
|
95
90
|
|
|
96
|
-
@TransformArgs(
|
|
91
|
+
@TransformArgs(authTransformers, { arg: 'input' })
|
|
97
92
|
@ValidateArgs(loginValidators, { arg: 'input', tKey: 'register' })
|
|
98
93
|
@Mutation(() => StatusPayload)
|
|
99
|
-
async login(@Arg('input') input:
|
|
94
|
+
async login(@Arg('input') input: AuthInput, @Ctx() ctx: TContext) {
|
|
100
95
|
const { t } = ctx;
|
|
101
|
-
const service = getAuthService();
|
|
96
|
+
const service = getAuthService(ctx);
|
|
102
97
|
const user = await service.db.findUserByEmail(input.email);
|
|
103
98
|
if (!user) throw new Error(t('validation:user.notFound'));
|
|
104
99
|
|
|
@@ -150,7 +145,7 @@ export function createAuthResolver<
|
|
|
150
145
|
@Arg('input') input: ConfirmEmailInput,
|
|
151
146
|
@Ctx() ctx: TContext
|
|
152
147
|
) {
|
|
153
|
-
const service = getAuthService();
|
|
148
|
+
const service = getAuthService(ctx);
|
|
154
149
|
const user = await service.getUserByToken(
|
|
155
150
|
AUTH_TOKEN_REDIS_PREFIX,
|
|
156
151
|
input.token
|
|
@@ -182,13 +177,12 @@ export function createAuthResolver<
|
|
|
182
177
|
return user;
|
|
183
178
|
}
|
|
184
179
|
|
|
185
|
-
|
|
186
180
|
@TransformArgs(sendTokenTransformers, { arg: 'input' })
|
|
187
181
|
@ValidateArgs(sendTokenValidators, { arg: 'input', tKey: 'sendToken' })
|
|
188
182
|
@Mutation(() => SendTokenPayload)
|
|
189
183
|
async sendToken(@Arg('input') input: SendTokenInput, @Ctx() ctx: TContext) {
|
|
190
184
|
const { t } = ctx;
|
|
191
|
-
const service = getAuthService();
|
|
185
|
+
const service = getAuthService(ctx);
|
|
192
186
|
const user = await service.db.findUserByEmail(input.email);
|
|
193
187
|
if (!user) throw new Error(t('validation:user.notFound'));
|
|
194
188
|
|
|
@@ -213,7 +207,7 @@ export function createAuthResolver<
|
|
|
213
207
|
@Arg('input') input: RecoverPasswordInput,
|
|
214
208
|
@Ctx() ctx: TContext
|
|
215
209
|
) {
|
|
216
|
-
const service = getAuthService();
|
|
210
|
+
const service = getAuthService(ctx);
|
|
217
211
|
const user = await service.getUserByToken(
|
|
218
212
|
AUTH_TOKEN_REDIS_PREFIX,
|
|
219
213
|
input.token
|
|
@@ -23,8 +23,10 @@ import {
|
|
|
23
23
|
updateProfileValidators,
|
|
24
24
|
} from '../dto';
|
|
25
25
|
|
|
26
|
-
export interface ProfileResolverDependencies
|
|
27
|
-
|
|
26
|
+
export interface ProfileResolverDependencies<
|
|
27
|
+
TContext extends ProfileContext = ProfileContext
|
|
28
|
+
> {
|
|
29
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
28
30
|
userType: any;
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -33,8 +35,8 @@ export function createProfileResolver<
|
|
|
33
35
|
>(deps: ProfileResolverDependencies): any {
|
|
34
36
|
const { authService, userType } = deps;
|
|
35
37
|
|
|
36
|
-
const getAuthService = (): ProfileAuthService => {
|
|
37
|
-
if (typeof authService === 'function') return authService();
|
|
38
|
+
const getAuthService = (ctx: TContext): ProfileAuthService => {
|
|
39
|
+
if (typeof authService === 'function') return authService(ctx);
|
|
38
40
|
return authService;
|
|
39
41
|
};
|
|
40
42
|
|
|
@@ -51,7 +53,7 @@ export function createProfileResolver<
|
|
|
51
53
|
const { user, t } = ctx;
|
|
52
54
|
if (!user) throw new UnauthorizedError();
|
|
53
55
|
|
|
54
|
-
const service = getAuthService();
|
|
56
|
+
const service = getAuthService(ctx);
|
|
55
57
|
if (await service.db.isEmailTaken(input.email, user.id)) {
|
|
56
58
|
throw new Error(t('validation:updateEmail.emailExists'));
|
|
57
59
|
}
|
|
@@ -77,7 +79,7 @@ export function createProfileResolver<
|
|
|
77
79
|
const { user, t } = ctx;
|
|
78
80
|
if (!user) throw new UnauthorizedError();
|
|
79
81
|
|
|
80
|
-
const service = getAuthService();
|
|
82
|
+
const service = getAuthService(ctx);
|
|
81
83
|
const isOldPasswordOk = await service.verifyPassword(
|
|
82
84
|
user.password!,
|
|
83
85
|
input.oldPassword
|
package/dist/dto/LoginInput.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import PasswordInput from './PasswordInput';
|
|
2
|
-
export default class LoginInput extends PasswordInput {
|
|
3
|
-
email: string;
|
|
4
|
-
}
|
|
5
|
-
export declare const loginValidators: {
|
|
6
|
-
email: import("@os-team/graphql-validators").Validator[];
|
|
7
|
-
password: import("@os-team/graphql-validators").Validator[];
|
|
8
|
-
};
|
|
9
|
-
export declare const loginTransformers: {
|
|
10
|
-
password: import("@os-team/graphql-transformers").Transformer[];
|
|
11
|
-
email: import("@os-team/graphql-transformers").Transformer[];
|
|
12
|
-
};
|
package/dist/dto/LoginInput.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.loginTransformers = exports.loginValidators = void 0;
|
|
46
|
-
const type_graphql_1 = require("type-graphql");
|
|
47
|
-
const graphql_validators_1 = require("@os-team/graphql-validators");
|
|
48
|
-
const graphql_transformers_1 = require("@os-team/graphql-transformers");
|
|
49
|
-
const PasswordInput_1 = __importStar(require("./PasswordInput"));
|
|
50
|
-
let LoginInput = class LoginInput extends PasswordInput_1.default {
|
|
51
|
-
};
|
|
52
|
-
__decorate([
|
|
53
|
-
(0, type_graphql_1.Field)(),
|
|
54
|
-
__metadata("design:type", String)
|
|
55
|
-
], LoginInput.prototype, "email", void 0);
|
|
56
|
-
LoginInput = __decorate([
|
|
57
|
-
(0, type_graphql_1.InputType)()
|
|
58
|
-
], LoginInput);
|
|
59
|
-
exports.default = LoginInput;
|
|
60
|
-
exports.loginValidators = {
|
|
61
|
-
email: [graphql_validators_1.isEmail],
|
|
62
|
-
password: [graphql_validators_1.isNotEmpty],
|
|
63
|
-
};
|
|
64
|
-
exports.loginTransformers = Object.assign({ email: [graphql_transformers_1.trim, graphql_transformers_1.toLowerCase] }, PasswordInput_1.passwordTransformers);
|
package/src/dto/LoginInput.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Field, InputType } from 'type-graphql';
|
|
2
|
-
import { isEmail, isNotEmpty } from '@os-team/graphql-validators';
|
|
3
|
-
import { toLowerCase, trim } from '@os-team/graphql-transformers';
|
|
4
|
-
import PasswordInput, { passwordTransformers } from './PasswordInput';
|
|
5
|
-
|
|
6
|
-
@InputType()
|
|
7
|
-
export default class LoginInput extends PasswordInput {
|
|
8
|
-
@Field()
|
|
9
|
-
email!: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const loginValidators = {
|
|
13
|
-
email: [isEmail],
|
|
14
|
-
password: [isNotEmpty],
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const loginTransformers = {
|
|
18
|
-
email: [trim, toLowerCase],
|
|
19
|
-
...passwordTransformers,
|
|
20
|
-
};
|