@semapps/auth 0.8.8 → 0.8.9
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/package.json +6 -6
- package/services/auth.local.js +20 -15
package/package.json
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@semapps/auth",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.9",
|
4
4
|
"description": "Authentification module for SemApps",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "Virtual Assembly",
|
7
7
|
"dependencies": {
|
8
|
-
"@semapps/ldp": "0.8.
|
9
|
-
"@semapps/middlewares": "0.8.
|
10
|
-
"@semapps/mime-types": "0.8.
|
11
|
-
"@semapps/triplestore": "0.8.
|
8
|
+
"@semapps/ldp": "0.8.9",
|
9
|
+
"@semapps/middlewares": "0.8.9",
|
10
|
+
"@semapps/mime-types": "0.8.9",
|
11
|
+
"@semapps/triplestore": "0.8.9",
|
12
12
|
"bcrypt": "^5.0.1",
|
13
13
|
"express-session": "^1.17.0",
|
14
14
|
"jsonwebtoken": "^8.5.1",
|
@@ -29,5 +29,5 @@
|
|
29
29
|
"engines": {
|
30
30
|
"node": ">=14"
|
31
31
|
},
|
32
|
-
"gitHead": "
|
32
|
+
"gitHead": "2a8bb8d6e5e1d37995d73ff75d8a7f5ab118ae56"
|
33
33
|
}
|
package/services/auth.local.js
CHANGED
@@ -51,7 +51,7 @@ const AuthLocalService = {
|
|
51
51
|
ctx.meta.skipObjectsWatcher = true;
|
52
52
|
|
53
53
|
if (username && username.length < 2) {
|
54
|
-
throw new
|
54
|
+
throw new MoleculerError('The username must be at least 2 characters long', 400, 'BAD_REQUEST');
|
55
55
|
}
|
56
56
|
|
57
57
|
let accountData = await ctx.call('auth.account.create', {
|
@@ -61,21 +61,27 @@ const AuthLocalService = {
|
|
61
61
|
...this.pickAccountData(rest)
|
62
62
|
});
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
try {
|
65
|
+
const profileData = { nick: username, email, ...rest };
|
66
|
+
const webId = await ctx.call('webid.createWebId', this.pickWebIdData(profileData), {
|
67
|
+
meta: {
|
68
|
+
isSignup: true // Allow services to handle directly the webId creation if it is generated by the AuthService
|
69
|
+
}
|
70
|
+
});
|
70
71
|
|
71
|
-
|
72
|
-
|
72
|
+
// Link the webId with the account
|
73
|
+
accountData = await ctx.call('auth.account.attachWebId', { accountUri: accountData['@id'], webId });
|
73
74
|
|
74
|
-
|
75
|
+
ctx.emit('auth.registered', { webId, profileData, accountData, interactionId });
|
75
76
|
|
76
|
-
|
77
|
+
const token = await ctx.call('auth.jwt.generateToken', { payload: { webId } });
|
77
78
|
|
78
|
-
|
79
|
+
return { token, webId, newUser: true };
|
80
|
+
} catch (e) {
|
81
|
+
// Delete account if resource creation failed, or it may cause problems when retrying
|
82
|
+
await ctx.call('auth.account.remove', { id: accountData['@id'] });
|
83
|
+
throw e;
|
84
|
+
}
|
79
85
|
},
|
80
86
|
async login(ctx) {
|
81
87
|
const { username, password, interactionId } = ctx.params;
|
@@ -117,7 +123,7 @@ const AuthLocalService = {
|
|
117
123
|
const account = await ctx.call('auth.account.findByEmail', { email });
|
118
124
|
|
119
125
|
if (!account) {
|
120
|
-
throw new
|
126
|
+
throw new MoleculerError('email.not.exists', 400, 'BAD_REQUEST');
|
121
127
|
}
|
122
128
|
|
123
129
|
const token = await ctx.call('auth.account.generateResetPasswordToken', { webId: account.webId });
|
@@ -133,7 +139,7 @@ const AuthLocalService = {
|
|
133
139
|
const account = await ctx.call('auth.account.findByEmail', { email });
|
134
140
|
|
135
141
|
if (!account) {
|
136
|
-
throw new
|
142
|
+
throw new MoleculerError('email.not.exists', 400, 'BAD_REQUEST');
|
137
143
|
}
|
138
144
|
|
139
145
|
await ctx.call('auth.account.setNewPassword', { webId: account.webId, token, password });
|
@@ -152,7 +158,6 @@ const AuthLocalService = {
|
|
152
158
|
done(null, returnedData);
|
153
159
|
})
|
154
160
|
.catch(e => {
|
155
|
-
console.error(e);
|
156
161
|
done(new MoleculerError(e.message, 401), false);
|
157
162
|
});
|
158
163
|
}
|