@skroz/profile-api 1.0.11 → 1.0.13
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/SendTokenInput.d.ts +10 -0
- package/dist/dto/SendTokenInput.js +31 -0
- package/dist/dto/SendTokenPayload.d.ts +1 -1
- package/dist/dto/SendTokenPayload.js +1 -1
- package/dist/dto/index.d.ts +1 -0
- package/dist/dto/index.js +5 -1
- package/dist/resolvers/AuthResolver.js +13 -13
- package/dist/services/ProfileAuthService.d.ts +1 -2
- package/dist/services/ProfileAuthService.js +4 -7
- package/dist/services/ProfileEmailService.js +2 -7
- package/dist/types/index.d.ts +6 -0
- package/package.json +2 -2
- package/src/dto/SendTokenInput.ts +18 -0
- package/src/dto/SendTokenPayload.ts +1 -1
- package/src/dto/index.ts +1 -0
- package/src/resolvers/AuthResolver.ts +16 -16
- package/src/services/ProfileAuthService.ts +3 -7
- package/src/services/ProfileEmailService.ts +2 -8
- package/src/types/index.ts +6 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare class SendTokenInput {
|
|
2
|
+
email: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const sendTokenValidators: {
|
|
5
|
+
email: import("@os-team/graphql-validators").Validator[];
|
|
6
|
+
};
|
|
7
|
+
export declare const sendTokenTransformers: {
|
|
8
|
+
email: import("@os-team/graphql-transformers").Transformer[];
|
|
9
|
+
};
|
|
10
|
+
export default SendTokenInput;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.sendTokenTransformers = exports.sendTokenValidators = void 0;
|
|
13
|
+
const type_graphql_1 = require("type-graphql");
|
|
14
|
+
const graphql_validators_1 = require("@os-team/graphql-validators");
|
|
15
|
+
const graphql_transformers_1 = require("@os-team/graphql-transformers");
|
|
16
|
+
let SendTokenInput = class SendTokenInput {
|
|
17
|
+
};
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, type_graphql_1.Field)(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], SendTokenInput.prototype, "email", void 0);
|
|
22
|
+
SendTokenInput = __decorate([
|
|
23
|
+
(0, type_graphql_1.InputType)()
|
|
24
|
+
], SendTokenInput);
|
|
25
|
+
exports.sendTokenValidators = {
|
|
26
|
+
email: [graphql_validators_1.isNotEmpty, graphql_validators_1.isEmail],
|
|
27
|
+
};
|
|
28
|
+
exports.sendTokenTransformers = {
|
|
29
|
+
email: [graphql_transformers_1.trim, graphql_transformers_1.toLowerCase],
|
|
30
|
+
};
|
|
31
|
+
exports.default = SendTokenInput;
|
|
@@ -15,7 +15,7 @@ let SendTokenPayload = class SendTokenPayload {
|
|
|
15
15
|
__decorate([
|
|
16
16
|
(0, type_graphql_1.Field)(),
|
|
17
17
|
__metadata("design:type", Boolean)
|
|
18
|
-
], SendTokenPayload.prototype, "
|
|
18
|
+
], SendTokenPayload.prototype, "codeIsSent", void 0);
|
|
19
19
|
__decorate([
|
|
20
20
|
(0, type_graphql_1.Field)(() => Number, { nullable: true }),
|
|
21
21
|
__metadata("design:type", Number)
|
package/dist/dto/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export { default as SendTokenPayload } from './SendTokenPayload';
|
|
|
8
8
|
export { default as UpdatePasswordInput, updatePasswordTransformers, updatePasswordValidators } from './UpdatePasswordInput';
|
|
9
9
|
export { default as UpdateEmailInput, updateEmailTransformers, updateEmailValidators } from './UpdateEmailInput';
|
|
10
10
|
export { default as UpdateProfileInput, updateProfileTransformers, updateProfileValidators } from './UpdateProfileInput';
|
|
11
|
+
export { default as SendTokenInput, sendTokenTransformers, sendTokenValidators } from './SendTokenInput';
|
|
11
12
|
export { default as RecoverPasswordInput, recoverPasswordTransformers, recoverPasswordValidators } from './RecoverPasswordInput';
|
package/dist/dto/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.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.loginValidators = exports.loginTransformers = exports.LoginInput = exports.registerValidators = exports.registerTransformers = exports.RegisterInput = exports.passwordValidators = exports.passwordTransformers = exports.PasswordInput = void 0;
|
|
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.loginValidators = exports.loginTransformers = exports.LoginInput = exports.registerValidators = exports.registerTransformers = exports.RegisterInput = 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; } });
|
|
@@ -39,6 +39,10 @@ var UpdateProfileInput_1 = require("./UpdateProfileInput");
|
|
|
39
39
|
Object.defineProperty(exports, "UpdateProfileInput", { enumerable: true, get: function () { return __importDefault(UpdateProfileInput_1).default; } });
|
|
40
40
|
Object.defineProperty(exports, "updateProfileTransformers", { enumerable: true, get: function () { return UpdateProfileInput_1.updateProfileTransformers; } });
|
|
41
41
|
Object.defineProperty(exports, "updateProfileValidators", { enumerable: true, get: function () { return UpdateProfileInput_1.updateProfileValidators; } });
|
|
42
|
+
var SendTokenInput_1 = require("./SendTokenInput");
|
|
43
|
+
Object.defineProperty(exports, "SendTokenInput", { enumerable: true, get: function () { return __importDefault(SendTokenInput_1).default; } });
|
|
44
|
+
Object.defineProperty(exports, "sendTokenTransformers", { enumerable: true, get: function () { return SendTokenInput_1.sendTokenTransformers; } });
|
|
45
|
+
Object.defineProperty(exports, "sendTokenValidators", { enumerable: true, get: function () { return SendTokenInput_1.sendTokenValidators; } });
|
|
42
46
|
var RecoverPasswordInput_1 = require("./RecoverPasswordInput");
|
|
43
47
|
Object.defineProperty(exports, "RecoverPasswordInput", { enumerable: true, get: function () { return __importDefault(RecoverPasswordInput_1).default; } });
|
|
44
48
|
Object.defineProperty(exports, "recoverPasswordTransformers", { enumerable: true, get: function () { return RecoverPasswordInput_1.recoverPasswordTransformers; } });
|
|
@@ -103,12 +103,12 @@ function createAuthResolver(deps) {
|
|
|
103
103
|
confirmEmail(input, ctx) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
105
|
const service = getAuthService();
|
|
106
|
-
const user = yield service.getUserByToken(ProfileAuthService_1.
|
|
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'));
|
|
109
109
|
user.isEmailConfirmed = true;
|
|
110
110
|
yield user.save();
|
|
111
|
-
yield service.removeTokenFromRedis(ProfileAuthService_1.
|
|
111
|
+
yield service.removeTokenFromRedis(ProfileAuthService_1.AUTH_TOKEN_REDIS_PREFIX, user, input.token);
|
|
112
112
|
const userAgent = decodeURI(ctx.req.get('user-agent') || '');
|
|
113
113
|
yield ctx.req.session.create({
|
|
114
114
|
userId: user.id,
|
|
@@ -123,19 +123,19 @@ function createAuthResolver(deps) {
|
|
|
123
123
|
return user;
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
sendToken(input, ctx) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
128
|
const { t } = ctx;
|
|
129
129
|
const service = getAuthService();
|
|
130
130
|
const user = yield service.db.findUserByEmail(input.email);
|
|
131
131
|
if (!user)
|
|
132
|
-
throw new Error(t('validation:
|
|
133
|
-
const res = yield service.sendLink(user, '
|
|
132
|
+
throw new Error(t('validation:user.notFound'));
|
|
133
|
+
const res = yield service.sendLink(user, 'confirmation');
|
|
134
134
|
if (logTelegramBot) {
|
|
135
|
-
yield logTelegramBot.sendError(
|
|
135
|
+
yield logTelegramBot.sendError(`Отправлен код верификации ${input.email}`);
|
|
136
136
|
}
|
|
137
137
|
return {
|
|
138
|
-
|
|
138
|
+
codeIsSent: res.ok,
|
|
139
139
|
limitExpiresAt: res.limitExpiresAt,
|
|
140
140
|
};
|
|
141
141
|
});
|
|
@@ -143,13 +143,13 @@ function createAuthResolver(deps) {
|
|
|
143
143
|
recoverPassword(input, ctx) {
|
|
144
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
145
|
const service = getAuthService();
|
|
146
|
-
const user = yield service.getUserByToken(ProfileAuthService_1.
|
|
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'));
|
|
149
149
|
user.password = yield service.hashPassword(input.password);
|
|
150
150
|
user.isTempPassword = false;
|
|
151
151
|
yield user.save();
|
|
152
|
-
yield service.removeTokenFromRedis(ProfileAuthService_1.
|
|
152
|
+
yield service.removeTokenFromRedis(ProfileAuthService_1.AUTH_TOKEN_REDIS_PREFIX, user, input.token);
|
|
153
153
|
const userAgent = decodeURI(ctx.req.get('user-agent') || '');
|
|
154
154
|
yield ctx.req.session.create({
|
|
155
155
|
userId: user.id,
|
|
@@ -206,15 +206,15 @@ function createAuthResolver(deps) {
|
|
|
206
206
|
__metadata("design:returntype", Promise)
|
|
207
207
|
], AuthResolver.prototype, "confirmEmail", null);
|
|
208
208
|
__decorate([
|
|
209
|
-
(0, graphql_transformers_1.TransformArgs)(dto_1.
|
|
210
|
-
(0, graphql_validators_1.ValidateArgs)(dto_1.
|
|
209
|
+
(0, graphql_transformers_1.TransformArgs)(dto_1.sendTokenTransformers, { arg: 'input' }),
|
|
210
|
+
(0, graphql_validators_1.ValidateArgs)(dto_1.sendTokenValidators, { arg: 'input', tKey: 'sendToken' }),
|
|
211
211
|
(0, type_graphql_1.Mutation)(() => dto_1.SendTokenPayload),
|
|
212
212
|
__param(0, (0, type_graphql_1.Arg)('input')),
|
|
213
213
|
__param(1, (0, type_graphql_1.Ctx)()),
|
|
214
214
|
__metadata("design:type", Function),
|
|
215
|
-
__metadata("design:paramtypes", [dto_1.
|
|
215
|
+
__metadata("design:paramtypes", [dto_1.SendTokenInput, Object]),
|
|
216
216
|
__metadata("design:returntype", Promise)
|
|
217
|
-
], AuthResolver.prototype, "
|
|
217
|
+
], AuthResolver.prototype, "sendToken", null);
|
|
218
218
|
__decorate([
|
|
219
219
|
(0, graphql_transformers_1.TransformArgs)(dto_1.recoverPasswordTransformers, { arg: 'input' }),
|
|
220
220
|
(0, graphql_validators_1.ValidateArgs)(dto_1.recoverPasswordValidators, { arg: 'input', tKey: 'recover' }),
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Redis } from 'ioredis';
|
|
2
2
|
import { AuthUser, ProfileAuthConfig, ProfileDbAdapter } from '../types';
|
|
3
3
|
import { ProfileEmailService } from './ProfileEmailService';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const RECOVERY_REDIS_PREFIX = "rec";
|
|
4
|
+
export declare const AUTH_TOKEN_REDIS_PREFIX = "auth";
|
|
6
5
|
export declare const TOKEN_REDIS_POSTFIX = "token";
|
|
7
6
|
export declare const LAST_SENT_AT_REDIS_POSTFIX = "lastSentAt";
|
|
8
7
|
export declare class ProfileAuthService {
|
|
@@ -12,10 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ProfileAuthService = exports.LAST_SENT_AT_REDIS_POSTFIX = exports.TOKEN_REDIS_POSTFIX = exports.
|
|
15
|
+
exports.ProfileAuthService = exports.LAST_SENT_AT_REDIS_POSTFIX = exports.TOKEN_REDIS_POSTFIX = exports.AUTH_TOKEN_REDIS_PREFIX = void 0;
|
|
16
16
|
const argon2_1 = __importDefault(require("argon2"));
|
|
17
|
-
exports.
|
|
18
|
-
exports.RECOVERY_REDIS_PREFIX = 'rec';
|
|
17
|
+
exports.AUTH_TOKEN_REDIS_PREFIX = 'auth';
|
|
19
18
|
exports.TOKEN_REDIS_POSTFIX = 'token';
|
|
20
19
|
exports.LAST_SENT_AT_REDIS_POSTFIX = 'lastSentAt';
|
|
21
20
|
class ProfileAuthService {
|
|
@@ -51,9 +50,7 @@ class ProfileAuthService {
|
|
|
51
50
|
}
|
|
52
51
|
sendLink(user, type) {
|
|
53
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const prefix =
|
|
55
|
-
? exports.CONFIRMATION_REDIS_PREFIX
|
|
56
|
-
: exports.RECOVERY_REDIS_PREFIX;
|
|
53
|
+
const prefix = exports.AUTH_TOKEN_REDIS_PREFIX;
|
|
57
54
|
const ttlMinutes = type === 'confirmation'
|
|
58
55
|
? this.config.confirmationTokenLifetimeMinutes
|
|
59
56
|
: this.config.recoveryTokenLifetimeMinutes;
|
|
@@ -80,7 +77,7 @@ class ProfileAuthService {
|
|
|
80
77
|
if (!userIdStr)
|
|
81
78
|
return null;
|
|
82
79
|
const userId = Number(userIdStr);
|
|
83
|
-
if (isNaN(userId))
|
|
80
|
+
if (Number.isNaN(userId))
|
|
84
81
|
return null;
|
|
85
82
|
return this.db.findUserById(userId);
|
|
86
83
|
});
|
|
@@ -64,13 +64,8 @@ class ProfileEmailService {
|
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
65
|
if (!user.email)
|
|
66
66
|
return false;
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
? this.locales.email.confirmEmail
|
|
70
|
-
: this.locales.email.forgotPassword;
|
|
71
|
-
const template = isConfirm
|
|
72
|
-
? types_1.ProfileEmailTemplate.CONFIRM_EMAIL
|
|
73
|
-
: types_1.ProfileEmailTemplate.FORGOT_PASSWORD;
|
|
67
|
+
const emailLocales = this.locales.email.verificationCode;
|
|
68
|
+
const template = types_1.ProfileEmailTemplate.CONFIRM_EMAIL;
|
|
74
69
|
return this.send(user.email, emailLocales.subject, template, {
|
|
75
70
|
header: emailLocales.header,
|
|
76
71
|
text: emailLocales.text,
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skroz/profile-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "git@gitlab.com:skroz/libs/utils.git",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"type-graphql": "^1.1.1",
|
|
44
44
|
"typeorm": "^0.2.45"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "64646f9451ea3748bf27f71a3112536a33f08493"
|
|
47
47
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
class SendTokenInput {
|
|
7
|
+
@Field()
|
|
8
|
+
public email!: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const sendTokenValidators = {
|
|
12
|
+
email: [isNotEmpty, isEmail],
|
|
13
|
+
};
|
|
14
|
+
export const sendTokenTransformers = {
|
|
15
|
+
email: [trim, toLowerCase],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default SendTokenInput;
|
package/src/dto/index.ts
CHANGED
|
@@ -8,4 +8,5 @@ export { default as SendTokenPayload } from './SendTokenPayload';
|
|
|
8
8
|
export { default as UpdatePasswordInput, updatePasswordTransformers, updatePasswordValidators } from './UpdatePasswordInput';
|
|
9
9
|
export { default as UpdateEmailInput, updateEmailTransformers, updateEmailValidators } from './UpdateEmailInput';
|
|
10
10
|
export { default as UpdateProfileInput, updateProfileTransformers, updateProfileValidators } from './UpdateProfileInput';
|
|
11
|
+
export { default as SendTokenInput, sendTokenTransformers, sendTokenValidators } from './SendTokenInput';
|
|
11
12
|
export { default as RecoverPasswordInput, recoverPasswordTransformers, recoverPasswordValidators } from './RecoverPasswordInput';
|
|
@@ -4,8 +4,7 @@ import { TransformArgs } from '@os-team/graphql-transformers';
|
|
|
4
4
|
import { ValidateArgs } from '@os-team/graphql-validators';
|
|
5
5
|
import {
|
|
6
6
|
ProfileAuthService,
|
|
7
|
-
|
|
8
|
-
RECOVERY_REDIS_PREFIX,
|
|
7
|
+
AUTH_TOKEN_REDIS_PREFIX,
|
|
9
8
|
} from '../services/ProfileAuthService';
|
|
10
9
|
import { ProfileContext } from '../types';
|
|
11
10
|
import {
|
|
@@ -24,6 +23,9 @@ import {
|
|
|
24
23
|
recoverPasswordValidators,
|
|
25
24
|
SendTokenPayload,
|
|
26
25
|
confirmEmailValidators,
|
|
26
|
+
SendTokenInput,
|
|
27
|
+
sendTokenTransformers,
|
|
28
|
+
sendTokenValidators,
|
|
27
29
|
} from '../dto';
|
|
28
30
|
|
|
29
31
|
export interface AuthResolverDependencies<
|
|
@@ -150,7 +152,7 @@ export function createAuthResolver<
|
|
|
150
152
|
) {
|
|
151
153
|
const service = getAuthService();
|
|
152
154
|
const user = await service.getUserByToken(
|
|
153
|
-
|
|
155
|
+
AUTH_TOKEN_REDIS_PREFIX,
|
|
154
156
|
input.token
|
|
155
157
|
);
|
|
156
158
|
if (!user) throw new Error(ctx.t('validation:error.wrongCode'));
|
|
@@ -158,7 +160,7 @@ export function createAuthResolver<
|
|
|
158
160
|
user.isEmailConfirmed = true;
|
|
159
161
|
await user.save();
|
|
160
162
|
await service.removeTokenFromRedis(
|
|
161
|
-
|
|
163
|
+
AUTH_TOKEN_REDIS_PREFIX,
|
|
162
164
|
user,
|
|
163
165
|
input.token
|
|
164
166
|
);
|
|
@@ -180,28 +182,26 @@ export function createAuthResolver<
|
|
|
180
182
|
return user;
|
|
181
183
|
}
|
|
182
184
|
|
|
183
|
-
|
|
184
|
-
@
|
|
185
|
+
|
|
186
|
+
@TransformArgs(sendTokenTransformers, { arg: 'input' })
|
|
187
|
+
@ValidateArgs(sendTokenValidators, { arg: 'input', tKey: 'sendToken' })
|
|
185
188
|
@Mutation(() => SendTokenPayload)
|
|
186
|
-
async
|
|
187
|
-
@Arg('input') input: ForgotPasswordInput,
|
|
188
|
-
@Ctx() ctx: TContext
|
|
189
|
-
) {
|
|
189
|
+
async sendToken(@Arg('input') input: SendTokenInput, @Ctx() ctx: TContext) {
|
|
190
190
|
const { t } = ctx;
|
|
191
191
|
const service = getAuthService();
|
|
192
192
|
const user = await service.db.findUserByEmail(input.email);
|
|
193
|
-
if (!user) throw new Error(t('validation:
|
|
193
|
+
if (!user) throw new Error(t('validation:user.notFound'));
|
|
194
194
|
|
|
195
|
-
const res = await service.sendLink(user, '
|
|
195
|
+
const res = await service.sendLink(user, 'confirmation');
|
|
196
196
|
|
|
197
197
|
if (logTelegramBot) {
|
|
198
198
|
await logTelegramBot.sendError(
|
|
199
|
-
|
|
199
|
+
`Отправлен код верификации ${input.email}`
|
|
200
200
|
);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
return {
|
|
204
|
-
|
|
204
|
+
codeIsSent: res.ok,
|
|
205
205
|
limitExpiresAt: res.limitExpiresAt,
|
|
206
206
|
};
|
|
207
207
|
}
|
|
@@ -215,7 +215,7 @@ export function createAuthResolver<
|
|
|
215
215
|
) {
|
|
216
216
|
const service = getAuthService();
|
|
217
217
|
const user = await service.getUserByToken(
|
|
218
|
-
|
|
218
|
+
AUTH_TOKEN_REDIS_PREFIX,
|
|
219
219
|
input.token
|
|
220
220
|
);
|
|
221
221
|
if (!user) throw new Error(ctx.t('validation:error.wrongCode'));
|
|
@@ -224,7 +224,7 @@ export function createAuthResolver<
|
|
|
224
224
|
user.isTempPassword = false;
|
|
225
225
|
await user.save();
|
|
226
226
|
await service.removeTokenFromRedis(
|
|
227
|
-
|
|
227
|
+
AUTH_TOKEN_REDIS_PREFIX,
|
|
228
228
|
user,
|
|
229
229
|
input.token
|
|
230
230
|
);
|
|
@@ -3,8 +3,7 @@ import { Redis } from 'ioredis';
|
|
|
3
3
|
import { AuthUser, ProfileAuthConfig, ProfileDbAdapter } from '../types';
|
|
4
4
|
import { ProfileEmailService } from './ProfileEmailService';
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
export const RECOVERY_REDIS_PREFIX = 'rec';
|
|
6
|
+
export const AUTH_TOKEN_REDIS_PREFIX = 'auth';
|
|
8
7
|
export const TOKEN_REDIS_POSTFIX = 'token';
|
|
9
8
|
export const LAST_SENT_AT_REDIS_POSTFIX = 'lastSentAt';
|
|
10
9
|
|
|
@@ -68,10 +67,7 @@ export class ProfileAuthService {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
async sendLink(user: AuthUser, type: 'confirmation' | 'recovery') {
|
|
71
|
-
const prefix =
|
|
72
|
-
type === 'confirmation'
|
|
73
|
-
? CONFIRMATION_REDIS_PREFIX
|
|
74
|
-
: RECOVERY_REDIS_PREFIX;
|
|
70
|
+
const prefix = AUTH_TOKEN_REDIS_PREFIX;
|
|
75
71
|
const ttlMinutes =
|
|
76
72
|
type === 'confirmation'
|
|
77
73
|
? this.config.confirmationTokenLifetimeMinutes
|
|
@@ -107,7 +103,7 @@ export class ProfileAuthService {
|
|
|
107
103
|
if (!userIdStr) return null;
|
|
108
104
|
|
|
109
105
|
const userId = Number(userIdStr);
|
|
110
|
-
if (isNaN(userId)) return null;
|
|
106
|
+
if (Number.isNaN(userId)) return null;
|
|
111
107
|
|
|
112
108
|
return this.db.findUserById(userId);
|
|
113
109
|
}
|
|
@@ -87,14 +87,8 @@ export class ProfileEmailService {
|
|
|
87
87
|
) {
|
|
88
88
|
if (!user.email) return false;
|
|
89
89
|
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
? this.locales.email.confirmEmail
|
|
93
|
-
: this.locales.email.forgotPassword;
|
|
94
|
-
|
|
95
|
-
const template = isConfirm
|
|
96
|
-
? ProfileEmailTemplate.CONFIRM_EMAIL
|
|
97
|
-
: ProfileEmailTemplate.FORGOT_PASSWORD;
|
|
90
|
+
const emailLocales = this.locales.email.verificationCode;
|
|
91
|
+
const template = ProfileEmailTemplate.CONFIRM_EMAIL;
|
|
98
92
|
|
|
99
93
|
return this.send(
|
|
100
94
|
user.email,
|
package/src/types/index.ts
CHANGED