192 lines
4.6 KiB
JavaScript
192 lines
4.6 KiB
JavaScript
const Joi = require('joi');
|
|
const controller = require('../controllers/auth.controller');
|
|
|
|
const authPayload = Joi.object({
|
|
email: Joi.string().email().required(),
|
|
password: Joi.string().min(6).required(),
|
|
teamName: Joi.string().min(1).required(),
|
|
firstName: Joi.string(),
|
|
lastName: Joi.string(),
|
|
organizationName: Joi.string(),
|
|
});
|
|
|
|
const refreshPayload = Joi.object({
|
|
refreshToken: Joi.string().required(),
|
|
});
|
|
|
|
const forgotPayload = Joi.object({
|
|
email: Joi.string().email().required(),
|
|
});
|
|
|
|
const resetPayload = Joi.object({
|
|
token: Joi.string().required(),
|
|
newPassword: Joi.string().min(6).required(),
|
|
});
|
|
|
|
const notificationSettingsPayload = Joi.object({
|
|
emailRegistration: Joi.boolean(),
|
|
emailFeedback: Joi.boolean(),
|
|
emailPayment: Joi.boolean(),
|
|
emailSummary: Joi.boolean(),
|
|
pushRegistration: Joi.boolean(),
|
|
pushSession: Joi.boolean(),
|
|
pushMessage: Joi.boolean(),
|
|
digestFrequency: Joi.string().valid('None', 'Daily', 'Weekly', 'Monthly'),
|
|
});
|
|
|
|
const updateMePayload = Joi.object({
|
|
firstName: Joi.string().allow('', null),
|
|
lastName: Joi.string().allow('', null),
|
|
phone: Joi.string().allow('', null),
|
|
profileImage: Joi.string().allow('', null),
|
|
bio: Joi.string().allow('', null),
|
|
notificationSettings: notificationSettingsPayload,
|
|
}).min(1);
|
|
|
|
const changePasswordPayload = Joi.object({
|
|
currentPassword: Joi.string().required(),
|
|
newPassword: Joi.string().min(8).required(),
|
|
});
|
|
|
|
const tokenPayload = Joi.object({
|
|
token: Joi.string().required(),
|
|
});
|
|
|
|
const disable2faPayload = Joi.object({
|
|
currentPassword: Joi.string().required(),
|
|
token: Joi.string().allow('', null),
|
|
});
|
|
|
|
const login2faPayload = Joi.object({
|
|
twoFactorToken: Joi.string().required(),
|
|
token: Joi.string().required(),
|
|
});
|
|
|
|
module.exports = [
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/register',
|
|
options: {
|
|
auth: false,
|
|
validate: { payload: authPayload },
|
|
handler: controller.register,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/login',
|
|
options: {
|
|
auth: false,
|
|
validate: {
|
|
payload: Joi.object({
|
|
email: Joi.string().email().required(),
|
|
password: Joi.string().required(),
|
|
}),
|
|
},
|
|
handler: controller.login,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/google',
|
|
options: {
|
|
auth: false,
|
|
validate: {
|
|
payload: Joi.object({
|
|
idToken: Joi.string().required(),
|
|
}),
|
|
},
|
|
handler: controller.googleLogin,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/google/register',
|
|
options: {
|
|
auth: false,
|
|
validate: {
|
|
payload: Joi.object({
|
|
idToken: Joi.string().required(),
|
|
teamName: Joi.string().min(1).allow('', null).optional(),
|
|
firstName: Joi.string().allow('', null),
|
|
lastName: Joi.string().allow('', null),
|
|
phone: Joi.string().allow('', null),
|
|
organizationName: Joi.string(),
|
|
}),
|
|
},
|
|
handler: controller.googleRegister,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/login/2fa',
|
|
options: {
|
|
auth: false,
|
|
validate: { payload: login2faPayload },
|
|
handler: controller.login2fa,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/refresh',
|
|
options: {
|
|
auth: false,
|
|
validate: { payload: refreshPayload },
|
|
handler: controller.refresh,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/logout',
|
|
options: { handler: controller.logout },
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/forgot-password',
|
|
options: {
|
|
auth: false,
|
|
validate: { payload: forgotPayload },
|
|
handler: controller.forgotPassword,
|
|
},
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/reset-password',
|
|
options: {
|
|
auth: false,
|
|
validate: { payload: resetPayload },
|
|
handler: controller.resetPassword,
|
|
},
|
|
},
|
|
{
|
|
method: 'GET',
|
|
path: '/api/auth/me',
|
|
options: { handler: controller.me },
|
|
},
|
|
{
|
|
method: 'PUT',
|
|
path: '/api/auth/me',
|
|
options: { validate: { payload: updateMePayload }, handler: controller.updateMe },
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/change-password',
|
|
options: { validate: { payload: changePasswordPayload }, handler: controller.changePassword },
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/2fa/setup',
|
|
options: { handler: controller.setup2fa },
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/2fa/verify-setup',
|
|
options: { validate: { payload: tokenPayload }, handler: controller.verify2faSetup },
|
|
},
|
|
{
|
|
method: 'POST',
|
|
path: '/api/auth/2fa/disable',
|
|
options: { validate: { payload: disable2faPayload }, handler: controller.disable2fa },
|
|
},
|
|
];
|