@aeriajs/builtins 0.0.284 → 0.0.285
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/authentication.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { throwIfError } from '@aeriajs/common';
|
|
1
2
|
import { signToken } from '@aeriajs/core';
|
|
2
3
|
export const AuthenticationError = {
|
|
3
4
|
InvalidCredentials: 'INVALID_CREDENTIALS',
|
|
@@ -27,7 +28,7 @@ export const successfulAuthentication = async (user, context) => {
|
|
|
27
28
|
}
|
|
28
29
|
tokenContent.userinfo = userinfo;
|
|
29
30
|
}
|
|
30
|
-
const token = await signToken(tokenContent);
|
|
31
|
+
const token = throwIfError(await signToken(tokenContent));
|
|
31
32
|
return {
|
|
32
33
|
user,
|
|
33
34
|
token: {
|
|
@@ -37,11 +38,11 @@ export const successfulAuthentication = async (user, context) => {
|
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
export const defaultSuccessfulAuthentication = async () => {
|
|
40
|
-
const token = await signToken({
|
|
41
|
+
const token = throwIfError(await signToken({
|
|
41
42
|
sub: null,
|
|
42
43
|
roles: ['root'],
|
|
43
44
|
userinfo: {},
|
|
44
|
-
});
|
|
45
|
+
}));
|
|
45
46
|
return {
|
|
46
47
|
user: {
|
|
47
48
|
_id: null,
|
|
@@ -79,8 +79,8 @@ export const activate = async (payload, context) => {
|
|
|
79
79
|
code: ActivationError.AlreadyActiveUser,
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
82
|
+
const { error } = await decodeToken(token, context.config.secret);
|
|
83
|
+
if (error) {
|
|
84
84
|
return context.error(HTTPStatus.Unauthorized, {
|
|
85
85
|
code: ActivationError.InvalidToken,
|
|
86
86
|
});
|
|
@@ -108,7 +108,7 @@ export const authenticate = async (props, context) => {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
const decodedToken = token
|
|
111
|
-
? await decodeToken(token.content)
|
|
111
|
+
? throwIfError(await decodeToken(token.content))
|
|
112
112
|
: context.token;
|
|
113
113
|
if (!decodedToken.sub) {
|
|
114
114
|
return Result.result(await defaultSuccessfulAuthentication());
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { throwIfError } from '@aeriajs/common';
|
|
1
2
|
import { signToken } from '@aeriajs/core';
|
|
2
3
|
import { Result, HTTPStatus, defineContract, resultSchema, endpointErrorSchema, functionSchemas } from '@aeriajs/types';
|
|
3
4
|
import { ActivationError } from './activate.js';
|
|
@@ -44,11 +45,11 @@ export const getActivationToken = async (userId, context) => {
|
|
|
44
45
|
if (!context.config.secret) {
|
|
45
46
|
throw new Error('config.secret is not set');
|
|
46
47
|
}
|
|
47
|
-
const token = await signToken({
|
|
48
|
+
const token = throwIfError(await signToken({
|
|
48
49
|
data: userId,
|
|
49
50
|
}, context.config.secret, {
|
|
50
51
|
expiresIn: context.config.security.linkTokenExpiration,
|
|
51
|
-
});
|
|
52
|
+
}));
|
|
52
53
|
return token;
|
|
53
54
|
};
|
|
54
55
|
export const getActivationLink = async (payload, context) => {
|
|
@@ -80,8 +80,8 @@ export const redefinePassword = async (payload, context) => {
|
|
|
80
80
|
code: RedefinePasswordError.UserNotActive,
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
83
|
+
const { error } = await decodeToken(token, context.config.secret);
|
|
84
|
+
if (error) {
|
|
85
85
|
return context.error(HTTPStatus.Unauthorized, {
|
|
86
86
|
code: RedefinePasswordError.InvalidToken,
|
|
87
87
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/builtins",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.285",
|
|
5
5
|
"description": "## Installation",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@aeriajs/common": "^0.0.161",
|
|
45
|
-
"@aeriajs/core": "^0.0.
|
|
45
|
+
"@aeriajs/core": "^0.0.285",
|
|
46
46
|
"@aeriajs/entrypoint": "^0.0.169",
|
|
47
47
|
"@aeriajs/types": "^0.0.137",
|
|
48
48
|
"@aeriajs/validation": "^0.0.185"
|