Skip to content

Commit b577376

Browse files
committed
fix authentication and logout
1 parent e2c3dc2 commit b577376

File tree

14 files changed

+27
-32
lines changed

14 files changed

+27
-32
lines changed

keys/private.pem.example

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
-----BEGIN RSA PRIVATE KEY-----
2-
MIICXAIBAAKBgQC0l9II745oaw+6EF+cZdBsvF4AAcKC+7AxUbcgUIH8hahApLwQ
3-
maeglUmnErumDu4aVEvHaWYvBBS2/Bc+mCGiadUegwahrUOX3g3FNQiNCWAdSBDM
4-
gwEctmlNQUh6OenceaBpQayIYIiOXgZRF28koy2dkiNp/gfqnClkBcArqwIDAQAB
5-
AoGAIW2U2EiXgKaIo7VSLV3/RZFciP3KZnp2M7rffeDJHtgSu9yCX0RB7gyUNJPY
6-
HjXXRxJhcIkG/B7yQqjJGLIKT3jdfFZh5TcJxbJI4+dPfcJCx4i+nXej25qYLalC
7-
ebgQs+xf3Qv5MAAGoLPqqee/MrBPyh31N85MqT0TqUnxcuECQQDvd39FIM6NiYEH
8-
u39S/wGnpQKU9qYlugNDId738nsC+53NtPeVIiM/87uctIvCFRiHblZ7ynyNhj7g
9-
uGtXX0QRAkEAwQ+/cpuoAxHBqhkqFgw5G0cgcx1lLre96s+Pg67HDFYCICNhDF08
10-
OajVp+daNMQ/0iwTU7qTbKfrTMIlk1R/+wJAKBkcaJjrvWuO/Zp54Y3t2wKYghUj
11-
ESIqta0QRviFfKRhcjahVomW2XiYq87XsDIUH2lsdeIcJR6bnMmEv+al4QJBAJd8
12-
o9xqBwthg3TVChECxkyBIxUwm5Rs2LjG5PWOzuD/G+vb1uq8veUAdaWqAz4kP2/K
13-
5d9tJwC7QgaY0KMqSsECQA+fDl+XOABmQFLITnjN31Zc6rArhgS/wFeO1MU/5oVL
14-
H0aH8xIM+eHPNnQrqct0aTmO2CnbbqoZlXoE4G6glVo=
2+
MIIBOgIBAAJBAJ6P+APtBxacEuI6n3PbdIDsLR2/uj/FVincMBYKBtpc3jBL/JNp
3+
qX10mmdkOpOv6Jh0vE314q9Zg88jSNjus9kCAwEAAQJAZ3W09IrSVzRbNfXeWPBW
4+
olB4V7LkSfvu7r1XOuor8ooi7cHyHAmaYu7LmcG41wE37BKkUG5+PTW3Q6qyIOqq
5+
IQIhANERd9yfuV57Tvv4eNHeIBPzpa2PUYCkOqYng9cfPR4dAiEAwigUJYUCeY6i
6+
SwlLcV+eFdGDd9n10iy3v9hXmyGUr+0CIDO8mObV9+9zoFYmZO+6gkGtt8A9iTPG
7+
cGURvkSMDHnZAiBy65QZLSRs3M8VCPhdr9H7ahqd6yYEdDGC3UPlb7f5dQIhAM6Q
8+
HzyFgXw46pPHHfiTH5bNt6Ms97plq1waZcwMtwfT
159
-----END RSA PRIVATE KEY-----

keys/public.pem.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-----BEGIN PUBLIC KEY-----
2-
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIyPdrgt0HmEwGblU18SddVY1JHky3wS
3-
/kCrsTT6wr6jOFMR6QTw1puBzposESpMXLj4thbM2Rhl0XVRiYUJONkCAwEAAQ==
4-
-----END PUBLIC KEY-----
1+
-----BEGIN RSA PUBLIC KEY-----
2+
MEgCQQCej/gD7QcWnBLiOp9z23SA7C0dv7o/xVYp3DAWCgbaXN4wS/yTaal9dJpn
3+
ZDqTr+iYdLxN9eKvWYPPI0jY7rPZAgMBAAE=
4+
-----END RSA PUBLIC KEY-----

src/auth/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export default {
77
}).unknown(true),
88
auth: Joi.object().keys({
99
'x-access-token': Joi.string().required().min(1),
10-
'x-user-id': JoiObjectId,
10+
'x-user-id': JoiObjectId(),
1111
}).unknown(true)
1212
};

src/helpers/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export enum ValidationSource {
1111
PARAM = 'params'
1212
}
1313

14-
export const JoiObjectId = () => Joi.string().custom((value: string, helpers) => {
14+
export const JoiObjectId = () => Joi.string().required().custom((value: string, helpers) => {
1515
if (!Types.ObjectId.isValid(value))
1616
return helpers.error('any.invalid');
1717
return value;

src/routes/v1/access/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ router.post('/basic', validator(schema.userCredential),
2929
const tokens = await createTokens(user, accessTokenKey, refreshTokenKey);
3030

3131
new SuccessResponse('Login Success', {
32-
user: _.pick(user, ['name', 'email']),
32+
user: _.pick(user, ['_id', 'name', 'roles', 'profilePicUrl']),
3333
tokens: tokens
3434
}).send(res);
3535
}));

src/routes/v1/access/logout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const router = express.Router();
88

99
/*-------------------------------------------------------------------------*/
1010
// Below all APIs are private APIs protected for Access Token
11-
router.use('/', require('../../../auth/Authentication'));
11+
router.use('/', require('../../../auth/authentication'));
1212
/*-------------------------------------------------------------------------*/
1313

1414
router.delete('/',

src/routes/v1/access/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
}),
1212
auth: Joi.object().keys({
1313
'x-access-token': Joi.string().required().min(1),
14-
'x-user-id': JoiObjectId,
14+
'x-user-id': JoiObjectId(),
1515
}).unknown(true),
1616
signup: Joi.object().keys({
1717
name: Joi.string().required().min(3),

src/routes/v1/access/signup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ router.post('/basic', validator(schema.signup),
3333

3434
const tokens = await createTokens(createdUser, keystore.primaryKey, keystore.secondaryKey);
3535
new SuccessResponse('Signup Successful', {
36-
user: _.pick(createdUser, ['name', 'email', 'roles', 'profilePicUrl']),
36+
user: _.pick(createdUser, ['_id', 'name', 'email', 'roles', 'profilePicUrl']),
3737
tokens: tokens,
3838
}).send(res);
3939
}));

src/routes/v1/blog/editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const router = express.Router();
1515
/*-------------------------------------------------------------------------*/
1616
// Below all APIs are private APIs protected for Access Token and Editor's Role
1717
router.use('/',
18-
require('../../../auth/Authentication'),
18+
require('../../../auth/authentication'),
1919
(req: RoleRequest, res, next) => { req.currentRoleCode = RoleCode.EDITOR; next(); },
20-
require('../../../auth/Authorization'));
20+
require('../../../auth/authorization'));
2121
/*-------------------------------------------------------------------------*/
2222

2323
router.put('/publish/:id', validator(schema.blogId, ValidationSource.PARAM),

src/routes/v1/blog/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
url: Joi.string().required().uri()
77
}),
88
blogId: Joi.object().keys({
9-
id: JoiObjectId
9+
id: JoiObjectId()
1010
}),
1111
blogTag: Joi.object().keys({
1212
tag: Joi.string().required().min(1)
@@ -16,7 +16,7 @@ export default {
1616
pageItemCount: Joi.number().required().integer().min(1),
1717
}),
1818
authorId: Joi.object().keys({
19-
id: JoiObjectId
19+
id: JoiObjectId()
2020
}),
2121
blogCreate: Joi.object().keys({
2222
title: Joi.string().required().min(3).max(500),

0 commit comments

Comments
 (0)