@skroz/profile-api 1.0.18 → 1.0.19
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/oauth/AppleOauth.d.ts +1 -0
- package/dist/oauth/AppleOauth.js +3 -0
- package/dist/oauth/GoogleOauth.d.ts +1 -0
- package/dist/oauth/GoogleOauth.js +1 -0
- package/dist/oauth/MailOauth.d.ts +1 -0
- package/dist/oauth/MailOauth.js +1 -0
- package/dist/oauth/OAuthProvider.d.ts +8 -0
- package/dist/oauth/VKOauth.d.ts +1 -0
- package/dist/oauth/VKOauth.js +3 -0
- package/dist/oauth/YandexOauth.d.ts +1 -0
- package/dist/oauth/YandexOauth.js +1 -0
- package/dist/resolvers/createOauthResolver.js +6 -0
- package/package.json +2 -2
- package/src/oauth/AppleOauth.ts +4 -0
- package/src/oauth/GoogleOauth.ts +2 -0
- package/src/oauth/MailOauth.ts +2 -0
- package/src/oauth/OAuthProvider.ts +8 -0
- package/src/oauth/VKOauth.ts +4 -0
- package/src/oauth/YandexOauth.ts +2 -0
- package/src/resolvers/createOauthResolver.ts +7 -0
package/dist/oauth/AppleOauth.js
CHANGED
|
@@ -47,6 +47,9 @@ function decodeJwtPayload(token) {
|
|
|
47
47
|
class AppleOauth {
|
|
48
48
|
constructor(config) {
|
|
49
49
|
this.config = config;
|
|
50
|
+
// Apple provides email only on first authorization. On subsequent logins email will be null,
|
|
51
|
+
// so confirmation flags are only set when email is actually present in the profile.
|
|
52
|
+
this.trustedEmail = true;
|
|
50
53
|
}
|
|
51
54
|
exchangeCode(code) {
|
|
52
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -17,6 +17,7 @@ const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
|
|
|
17
17
|
class GoogleOauth {
|
|
18
18
|
constructor(config) {
|
|
19
19
|
this.config = config;
|
|
20
|
+
this.trustedEmail = true;
|
|
20
21
|
}
|
|
21
22
|
exchangeCode(code) {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/oauth/MailOauth.js
CHANGED
|
@@ -6,4 +6,12 @@ export interface OAuthProfile {
|
|
|
6
6
|
}
|
|
7
7
|
export interface OAuthProvider {
|
|
8
8
|
exchangeCode(code: string): Promise<OAuthProfile>;
|
|
9
|
+
/**
|
|
10
|
+
* Whether this provider verifies the user's email address.
|
|
11
|
+
* When true, isEmailConfirmed and isEmailNotificationEnabled are automatically
|
|
12
|
+
* set to true upon login/registration via this provider.
|
|
13
|
+
*
|
|
14
|
+
* Set to false for providers that do not supply a verified email (e.g. Telegram).
|
|
15
|
+
*/
|
|
16
|
+
readonly trustedEmail: boolean;
|
|
9
17
|
}
|
package/dist/oauth/VKOauth.d.ts
CHANGED
package/dist/oauth/VKOauth.js
CHANGED
|
@@ -17,6 +17,9 @@ const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
|
|
|
17
17
|
class VKOauth {
|
|
18
18
|
constructor(config) {
|
|
19
19
|
this.config = config;
|
|
20
|
+
// VK returns email only if the user has a confirmed email in their account and grants access.
|
|
21
|
+
// If email is absent, trustedEmail guard in the resolver prevents setting confirmation flags.
|
|
22
|
+
this.trustedEmail = true;
|
|
20
23
|
}
|
|
21
24
|
exchangeCode(code) {
|
|
22
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -17,6 +17,7 @@ const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));
|
|
|
17
17
|
class YandexOauth {
|
|
18
18
|
constructor(config) {
|
|
19
19
|
this.config = config;
|
|
20
|
+
this.trustedEmail = true;
|
|
20
21
|
}
|
|
21
22
|
exchangeCode(code) {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -114,6 +114,12 @@ function createOauthResolver(deps) {
|
|
|
114
114
|
yield service.db.updateUserProviderId(user.id, input.provider, profile.providerId);
|
|
115
115
|
isNew = true;
|
|
116
116
|
}
|
|
117
|
+
// Auto-confirm email for trusted providers when email is present
|
|
118
|
+
if (provider.trustedEmail && profile.email && (!user.isEmailConfirmed || !user.isEmailNotificationEnabled)) {
|
|
119
|
+
user.isEmailConfirmed = true;
|
|
120
|
+
user.isEmailNotificationEnabled = true;
|
|
121
|
+
yield user.save();
|
|
122
|
+
}
|
|
117
123
|
}
|
|
118
124
|
if (user.isBanned)
|
|
119
125
|
throw new Error('User is banned');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skroz/profile-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "git@gitlab.com:skroz/libs/utils.git",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"type-graphql": "^1.1.1",
|
|
45
45
|
"typeorm": "^0.2.45"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "ad9d511d8f623ad1a5d3a6a83e016c4b12d4f211"
|
|
48
48
|
}
|
package/src/oauth/AppleOauth.ts
CHANGED
|
@@ -43,6 +43,10 @@ function decodeJwtPayload(token: string): Record<string, any> {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export class AppleOauth implements OAuthProvider {
|
|
46
|
+
// Apple provides email only on first authorization. On subsequent logins email will be null,
|
|
47
|
+
// so confirmation flags are only set when email is actually present in the profile.
|
|
48
|
+
readonly trustedEmail = true;
|
|
49
|
+
|
|
46
50
|
constructor(private config: AppleOauthConfig) {}
|
|
47
51
|
|
|
48
52
|
async exchangeCode(code: string): Promise<OAuthProfile> {
|
package/src/oauth/GoogleOauth.ts
CHANGED
package/src/oauth/MailOauth.ts
CHANGED
|
@@ -7,4 +7,12 @@ export interface OAuthProfile {
|
|
|
7
7
|
|
|
8
8
|
export interface OAuthProvider {
|
|
9
9
|
exchangeCode(code: string): Promise<OAuthProfile>;
|
|
10
|
+
/**
|
|
11
|
+
* Whether this provider verifies the user's email address.
|
|
12
|
+
* When true, isEmailConfirmed and isEmailNotificationEnabled are automatically
|
|
13
|
+
* set to true upon login/registration via this provider.
|
|
14
|
+
*
|
|
15
|
+
* Set to false for providers that do not supply a verified email (e.g. Telegram).
|
|
16
|
+
*/
|
|
17
|
+
readonly trustedEmail: boolean;
|
|
10
18
|
}
|
package/src/oauth/VKOauth.ts
CHANGED
|
@@ -8,6 +8,10 @@ interface VKOauthConfig {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export class VKOauth implements OAuthProvider {
|
|
11
|
+
// VK returns email only if the user has a confirmed email in their account and grants access.
|
|
12
|
+
// If email is absent, trustedEmail guard in the resolver prevents setting confirmation flags.
|
|
13
|
+
readonly trustedEmail = true;
|
|
14
|
+
|
|
11
15
|
constructor(private config: VKOauthConfig) {}
|
|
12
16
|
|
|
13
17
|
async exchangeCode(code: string): Promise<OAuthProfile> {
|
package/src/oauth/YandexOauth.ts
CHANGED
|
@@ -114,6 +114,13 @@ export function createOauthResolver<
|
|
|
114
114
|
await service.db.updateUserProviderId(user.id, input.provider, profile.providerId);
|
|
115
115
|
isNew = true;
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
// Auto-confirm email for trusted providers when email is present
|
|
119
|
+
if (provider.trustedEmail && profile.email && (!user.isEmailConfirmed || !user.isEmailNotificationEnabled)) {
|
|
120
|
+
user.isEmailConfirmed = true;
|
|
121
|
+
user.isEmailNotificationEnabled = true;
|
|
122
|
+
await user.save();
|
|
123
|
+
}
|
|
117
124
|
}
|
|
118
125
|
|
|
119
126
|
if (user.isBanned) throw new Error('User is banned');
|