@medusajs/auth-emailpass 0.0.2-snapshot-20240827104434 → 0.0.2-snapshot-20240904063643
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { AuthenticationInput, AuthenticationResponse, AuthIdentityProviderService, EmailPassAuthProviderOptions, Logger } from "@medusajs/types";
|
2
2
|
import { AbstractAuthModuleProvider } from "@medusajs/utils";
|
3
3
|
type InjectedDependencies = {
|
4
4
|
logger: Logger;
|
@@ -9,7 +9,13 @@ 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 createAuthIdentity({ email, password, authIdentityService }: {
|
13
|
+
email: any;
|
14
|
+
password: any;
|
15
|
+
authIdentityService: any;
|
16
|
+
}): Promise<any>;
|
12
17
|
authenticate(userData: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>;
|
18
|
+
register(userData: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>;
|
13
19
|
}
|
14
20
|
export {};
|
15
21
|
//# sourceMappingURL=emailpass.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"emailpass.d.ts","sourceRoot":"","sources":["../../src/services/emailpass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
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;IAoBrE,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,6 +12,20 @@ class EmailPassAuthService extends utils_1.AbstractAuthModuleProvider {
|
|
12
12
|
this.config_ = options;
|
13
13
|
this.logger_ = logger;
|
14
14
|
}
|
15
|
+
async createAuthIdentity({ email, password, authIdentityService }) {
|
16
|
+
const hashConfig = this.config_.hashConfig ?? { logN: 15, r: 8, p: 1 };
|
17
|
+
const passwordHash = await scrypt_kdf_1.default.kdf(password, hashConfig);
|
18
|
+
const createdAuthIdentity = await authIdentityService.create({
|
19
|
+
entity_id: email,
|
20
|
+
provider_metadata: {
|
21
|
+
password: passwordHash.toString("base64"),
|
22
|
+
},
|
23
|
+
});
|
24
|
+
const copy = JSON.parse(JSON.stringify(createdAuthIdentity));
|
25
|
+
const providerIdentity = copy.provider_identities?.find((pi) => pi.provider === this.provider);
|
26
|
+
delete providerIdentity.provider_metadata?.password;
|
27
|
+
return copy;
|
28
|
+
}
|
15
29
|
async authenticate(userData, authIdentityService) {
|
16
30
|
const { email, password } = userData.body ?? {};
|
17
31
|
if (!password || !(0, utils_1.isString)(password)) {
|
@@ -34,20 +48,9 @@ class EmailPassAuthService extends utils_1.AbstractAuthModuleProvider {
|
|
34
48
|
}
|
35
49
|
catch (error) {
|
36
50
|
if (error.type === utils_1.MedusaError.Types.NOT_FOUND) {
|
37
|
-
const config = this.config_.hashConfig ?? { logN: 15, r: 8, p: 1 };
|
38
|
-
const passwordHash = await scrypt_kdf_1.default.kdf(password, config);
|
39
|
-
const createdAuthIdentity = await authIdentityService.create({
|
40
|
-
entity_id: email,
|
41
|
-
provider_metadata: {
|
42
|
-
password: passwordHash.toString("base64"),
|
43
|
-
},
|
44
|
-
});
|
45
|
-
const copy = JSON.parse(JSON.stringify(createdAuthIdentity));
|
46
|
-
const providerIdentity = copy.provider_identities?.find((pi) => pi.provider === this.provider);
|
47
|
-
delete providerIdentity.provider_metadata?.password;
|
48
51
|
return {
|
49
|
-
success:
|
50
|
-
|
52
|
+
success: false,
|
53
|
+
error: "Invalid email or password",
|
51
54
|
};
|
52
55
|
}
|
53
56
|
return { success: false, error: error.message };
|
@@ -72,6 +75,44 @@ class EmailPassAuthService extends utils_1.AbstractAuthModuleProvider {
|
|
72
75
|
error: "Invalid email or password",
|
73
76
|
};
|
74
77
|
}
|
78
|
+
async register(userData, authIdentityService) {
|
79
|
+
const { email, password } = userData.body ?? {};
|
80
|
+
if (!password || !(0, utils_1.isString)(password)) {
|
81
|
+
return {
|
82
|
+
success: false,
|
83
|
+
error: "Password should be a string",
|
84
|
+
};
|
85
|
+
}
|
86
|
+
if (!email || !(0, utils_1.isString)(email)) {
|
87
|
+
return {
|
88
|
+
success: false,
|
89
|
+
error: "Email should be a string",
|
90
|
+
};
|
91
|
+
}
|
92
|
+
try {
|
93
|
+
await authIdentityService.retrieve({
|
94
|
+
entity_id: email,
|
95
|
+
});
|
96
|
+
return {
|
97
|
+
success: false,
|
98
|
+
error: "Identity with email already exists",
|
99
|
+
};
|
100
|
+
}
|
101
|
+
catch (error) {
|
102
|
+
if (error.type === utils_1.MedusaError.Types.NOT_FOUND) {
|
103
|
+
const createdAuthIdentity = await this.createAuthIdentity({
|
104
|
+
email,
|
105
|
+
password,
|
106
|
+
authIdentityService,
|
107
|
+
});
|
108
|
+
return {
|
109
|
+
success: true,
|
110
|
+
authIdentity: createdAuthIdentity,
|
111
|
+
};
|
112
|
+
}
|
113
|
+
return { success: false, error: error.message };
|
114
|
+
}
|
115
|
+
}
|
75
116
|
}
|
76
117
|
exports.EmailPassAuthService = EmailPassAuthService;
|
77
|
-
//# sourceMappingURL=data:application/json;base64,
|
118
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1haWxwYXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NlcnZpY2VzL2VtYWlscGFzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFRQSwyQ0FJd0I7QUFDeEIsNERBQStCO0FBUS9CLE1BQWEsb0JBQXFCLFNBQVEsa0NBQTBCO0lBSWxFLFlBQ0UsRUFBRSxNQUFNLEVBQXdCLEVBQ2hDLE9BQXFDO1FBRXJDLEtBQUssQ0FDSCxFQUFFLEVBQ0YsRUFBRSxRQUFRLEVBQUUsV0FBVyxFQUFFLFdBQVcsRUFBRSwrQkFBK0IsRUFBRSxDQUN4RSxDQUFBO1FBQ0QsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUE7UUFDdEIsSUFBSSxDQUFDLE9BQU8sR0FBRyxNQUFNLENBQUE7SUFDdkIsQ0FBQztJQUVTLEtBQUssQ0FBQyxrQkFBa0IsQ0FBQyxFQUFFLEtBQUssRUFBRSxRQUFRLEVBQUUsbUJBQW1CLEVBQUU7UUFDekUsTUFBTSxVQUFVLEdBQUcsSUFBSSxDQUFDLE9BQU8sQ0FBQyxVQUFVLElBQUksRUFBRSxJQUFJLEVBQUUsRUFBRSxFQUFFLENBQUMsRUFBRSxDQUFDLEVBQUUsQ0FBQyxFQUFFLENBQUMsRUFBRSxDQUFBO1FBQ3RFLE1BQU0sWUFBWSxHQUFHLE1BQU0sb0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LQUFLLElBQUksQ0FBQyxJQUFBLGdCQUFRLEVBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQztZQUMvQixPQUFPO2dCQUNMLE9BQU8sRUFBRSxLQUFLO2dCQUNkLEtBQUssRUFBRSwwQkFBMEI7YUFDbEMsQ0FBQTtRQUNILENBQUM7UUFFRCxJQUFJLENBQUM7WUFDSCxNQUFNLG1CQUFtQixDQUFDLFFBQVEsQ0FBQztnQkFDakMsU0FBUyxFQUFFLEtBQUs7YUFDakIsQ0FBQyxDQUFBO1lBRUYsT0FBTztnQkFDTCxPQUFPLEVBQUUsS0FBSztnQkFDZCxLQUFLLEVBQUUsb0NBQW9DO2FBQzVDLENBQUE7UUFDSCxDQUFDO1FBQUMsT0FBTyxLQUFLLEVBQUUsQ0FBQztZQUNmLElBQUksS0FBSyxDQUFDLElBQUksS0FBSyxtQkFBVyxDQUFDLEtBQUssQ0FBQyxTQUFTLEVBQUUsQ0FBQztnQkFDL0MsTUFBTSxtQkFBbUIsR0FBRyxNQUFNLElBQUksQ0FBQyxrQkFBa0IsQ0FBQztvQkFDeEQsS0FBSztvQkFDTCxRQUFRO29CQUNSLG1CQUFtQjtpQkFDcEIsQ0FBQyxDQUFBO2dCQUVGLE9BQU87b0JBQ0wsT0FBTyxFQUFFLElBQUk7b0JBQ2IsWUFBWSxFQUFFLG1CQUFtQjtpQkFDbEMsQ0FBQTtZQUNILENBQUM7WUFFRCxPQUFPLEVBQUUsT0FBTyxFQUFFLEtBQUssRUFBRSxLQUFLLEVBQUUsS0FBSyxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2pELENBQUM7SUFDSCxDQUFDO0NBQ0Y7QUFwSkQsb0RBb0pDIn0=
|
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-20240904063643",
|
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-20240904063643",
|
33
33
|
"scrypt-kdf": "^2.0.1"
|
34
34
|
},
|
35
35
|
"keywords": [
|