@medusajs/auth-emailpass 0.0.2-snapshot-20240905140403 → 0.0.2-snapshot-20240906131500
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,23 @@ export declare class EmailPassAuthService extends AbstractAuthModuleProvider {
|
|
9
9
|
protected config_: LocalServiceConfig;
|
10
10
|
protected logger_: Logger;
|
11
11
|
constructor({ logger }: InjectedDependencies, options: EmailPassAuthProviderOptions);
|
12
|
+
protected hashPassword(password: string): Promise<string>;
|
13
|
+
update(data: {
|
14
|
+
email: string;
|
15
|
+
password: string;
|
16
|
+
}, authIdentityService: AuthIdentityProviderService): Promise<{
|
17
|
+
success: boolean;
|
18
|
+
error?: undefined;
|
19
|
+
authIdentity?: undefined;
|
20
|
+
} | {
|
21
|
+
success: boolean;
|
22
|
+
error: any;
|
23
|
+
authIdentity?: undefined;
|
24
|
+
} | {
|
25
|
+
success: boolean;
|
26
|
+
authIdentity: any;
|
27
|
+
error?: undefined;
|
28
|
+
}>;
|
12
29
|
protected createAuthIdentity({ email, password, authIdentityService }: {
|
13
30
|
email: any;
|
14
31
|
password: any;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"emailpass.d.ts","sourceRoot":"","sources":["../../src/services/emailpass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EAEtB,2BAA2B,EAC3B,4BAA4B,EAC5B,MAAM,EACP,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,0BAA0B,EAG3B,MAAM,iBAAiB,CAAA;AAGxB,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,UAAU,kBAAmB,SAAQ,4BAA4B;CAAG;AAEpE,qBAAa,oBAAqB,SAAQ,0BAA0B;IAClE,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAA;IACrC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAGvB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAChC,OAAO,EAAE,4BAA4B;cAUvB,kBAAkB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE;;;;KAAA;
|
1
|
+
{"version":3,"file":"emailpass.d.ts","sourceRoot":"","sources":["../../src/services/emailpass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EAEtB,2BAA2B,EAC3B,4BAA4B,EAC5B,MAAM,EACP,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,0BAA0B,EAG3B,MAAM,iBAAiB,CAAA;AAGxB,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,UAAU,kBAAmB,SAAQ,4BAA4B;CAAG;AAEpE,qBAAa,oBAAqB,SAAQ,0BAA0B;IAClE,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAA;IACrC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAGvB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAChC,OAAO,EAAE,4BAA4B;cAUvB,YAAY,CAAC,QAAQ,EAAE,MAAM;IAMvC,MAAM,CACV,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EACzC,mBAAmB,EAAE,2BAA2B;;;;;;;;;;;;;cAmClC,kBAAkB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE;;;;KAAA;IAmBrE,YAAY,CAChB,QAAQ,EAAE,mBAAmB,EAC7B,mBAAmB,EAAE,2BAA2B,GAC/C,OAAO,CAAC,sBAAsB,CAAC;IA+D5B,QAAQ,CACZ,QAAQ,EAAE,mBAAmB,EAC7B,mBAAmB,EAAE,2BAA2B,GAC/C,OAAO,CAAC,sBAAsB,CAAC;CA2CnC"}
|
@@ -12,13 +12,45 @@ class EmailPassAuthService extends utils_1.AbstractAuthModuleProvider {
|
|
12
12
|
this.config_ = options;
|
13
13
|
this.logger_ = logger;
|
14
14
|
}
|
15
|
-
async
|
15
|
+
async hashPassword(password) {
|
16
16
|
const hashConfig = this.config_.hashConfig ?? { logN: 15, r: 8, p: 1 };
|
17
17
|
const passwordHash = await scrypt_kdf_1.default.kdf(password, hashConfig);
|
18
|
+
return passwordHash.toString("base64");
|
19
|
+
}
|
20
|
+
async update(data, authIdentityService) {
|
21
|
+
const { email, password } = data ?? {};
|
22
|
+
if (!email || !(0, utils_1.isString)(email)) {
|
23
|
+
return {
|
24
|
+
success: false,
|
25
|
+
error: `Cannot update ${this.provider} provider identity without email`,
|
26
|
+
};
|
27
|
+
}
|
28
|
+
if (!password || !(0, utils_1.isString)(password)) {
|
29
|
+
return { success: true };
|
30
|
+
}
|
31
|
+
let authIdentity;
|
32
|
+
try {
|
33
|
+
const passwordHash = await this.hashPassword(password);
|
34
|
+
authIdentity = await authIdentityService.update(email, {
|
35
|
+
provider_metadata: {
|
36
|
+
password: passwordHash,
|
37
|
+
},
|
38
|
+
});
|
39
|
+
}
|
40
|
+
catch (error) {
|
41
|
+
return { success: false, error: error.message };
|
42
|
+
}
|
43
|
+
return {
|
44
|
+
success: true,
|
45
|
+
authIdentity,
|
46
|
+
};
|
47
|
+
}
|
48
|
+
async createAuthIdentity({ email, password, authIdentityService }) {
|
49
|
+
const passwordHash = await this.hashPassword(password);
|
18
50
|
const createdAuthIdentity = await authIdentityService.create({
|
19
51
|
entity_id: email,
|
20
52
|
provider_metadata: {
|
21
|
-
password: passwordHash
|
53
|
+
password: passwordHash,
|
22
54
|
},
|
23
55
|
});
|
24
56
|
const copy = JSON.parse(JSON.stringify(createdAuthIdentity));
|
@@ -115,4 +147,4 @@ class EmailPassAuthService extends utils_1.AbstractAuthModuleProvider {
|
|
115
147
|
}
|
116
148
|
}
|
117
149
|
exports.EmailPassAuthService = EmailPassAuthService;
|
118
|
-
//# sourceMappingURL=data:application/json;base64,
|
150
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1haWxwYXNzLmpzIiwic291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BRSwwQkFBMEI7YUFDbEMsQ0FBQTtRQUNILENBQUM7UUFFRCxJQUFJLENBQUM7WUFDSCxNQUFNLG1CQUFtQixDQUFDLFFBQVEsQ0FBQztnQkFDakMsU0FBUyxFQUFFLEtBQUs7YUFDakIsQ0FBQyxDQUFBO1lBRUYsT0FBTztnQkFDTCxPQUFPLEVBQUUsS0FBSztnQkFDZCxLQUFLLEVBQUUsb0NBQW9DO2FBQzVDLENBQUE7UUFDSCxDQUFDO1FBQUMsT0FBTyxLQUFLLEVBQUUsQ0FBQztZQUNmLElBQUksS0FBSyxDQUFDLElBQUksS0FBSyxtQkFBVyxDQUFDLEtBQUssQ0FBQyxTQUFTLEVBQUUsQ0FBQztnQkFDL0MsTUFBTSxtQkFBbUIsR0FBRyxNQUFNLElBQUksQ0FBQyxrQkFBa0IsQ0FBQztvQkFDeEQsS0FBSztvQkFDTCxRQUFRO29CQUNSLG1CQUFtQjtpQkFDcEIsQ0FBQyxDQUFBO2dCQUVGLE9BQU87b0JBQ0wsT0FBTyxFQUFFLElBQUk7b0JBQ2IsWUFBWSxFQUFFLG1CQUFtQjtpQkFDbEMsQ0FBQTtZQUNILENBQUM7WUFFRCxPQUFPLEVBQUUsT0FBTyxFQUFFLEtBQUssRUFBRSxLQUFLLEVBQUUsS0FBSyxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2pELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUE5TEQsb0RBOExDIn0=
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/auth-emailpass",
|
3
|
-
"version": "0.0.2-snapshot-
|
3
|
+
"version": "0.0.2-snapshot-20240906131500",
|
4
4
|
"description": "Email and password credential authentication provider for Medusa",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"repository": {
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"typescript": "^5.3.3"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@medusajs/utils": "1.12.0-snapshot-
|
32
|
+
"@medusajs/utils": "1.12.0-snapshot-20240906131500",
|
33
33
|
"scrypt-kdf": "^2.0.1"
|
34
34
|
},
|
35
35
|
"keywords": [
|