cca-auth-module 0.1.84 → 0.1.86
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/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +86 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -85
- package/dist/index.mjs.map +1 -1
- package/dist/presentation/constants/constants.d.ts +21 -0
- package/dist/presentation/controller/AuthController.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -232,8 +232,9 @@ declare class AuthController {
|
|
|
232
232
|
private readonly twoFactorVerifyUseCase;
|
|
233
233
|
private readonly twoFactorDisableUseCase;
|
|
234
234
|
constructor(loginUseCase: LoginUseCase, adminLoginUseCase: LoginAdminUseCase, logoutUseCase: LogoutUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase, twoFactorSetupUseCase: TwoFactorSetupUseCase, twoFactorEnableUseCase: TwoFactorEnableUseCase, twoFactorVerifyUseCase: TwoFactorVerifyUseCase, twoFactorDisableUseCase: TwoFactorDisableUseCase);
|
|
235
|
-
private
|
|
235
|
+
private createResponse;
|
|
236
236
|
private createAuthData;
|
|
237
|
+
private sendResponse;
|
|
237
238
|
login: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
238
239
|
adminLogin: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
239
240
|
logout: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -232,8 +232,9 @@ declare class AuthController {
|
|
|
232
232
|
private readonly twoFactorVerifyUseCase;
|
|
233
233
|
private readonly twoFactorDisableUseCase;
|
|
234
234
|
constructor(loginUseCase: LoginUseCase, adminLoginUseCase: LoginAdminUseCase, logoutUseCase: LogoutUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase, twoFactorSetupUseCase: TwoFactorSetupUseCase, twoFactorEnableUseCase: TwoFactorEnableUseCase, twoFactorVerifyUseCase: TwoFactorVerifyUseCase, twoFactorDisableUseCase: TwoFactorDisableUseCase);
|
|
235
|
-
private
|
|
235
|
+
private createResponse;
|
|
236
236
|
private createAuthData;
|
|
237
|
+
private sendResponse;
|
|
237
238
|
login: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
238
239
|
adminLogin: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
239
240
|
logout: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -732,6 +732,29 @@ var _TwoFactorDisableUseCase = class _TwoFactorDisableUseCase {
|
|
|
732
732
|
__name(_TwoFactorDisableUseCase, "TwoFactorDisableUseCase");
|
|
733
733
|
var TwoFactorDisableUseCase = _TwoFactorDisableUseCase;
|
|
734
734
|
|
|
735
|
+
// src/presentation/constants/constants.ts
|
|
736
|
+
var HTTP_STATUS = {
|
|
737
|
+
OK: 200,
|
|
738
|
+
CREATED: 201
|
|
739
|
+
};
|
|
740
|
+
var AUTH_STATUS = {
|
|
741
|
+
BASIC_AUTH: "basic_auth",
|
|
742
|
+
NEEDS_SETUP: "needs_setup",
|
|
743
|
+
PENDING_VERIFICATION: "pending_verification",
|
|
744
|
+
FULL_AUTH: "full_auth"
|
|
745
|
+
};
|
|
746
|
+
var MESSAGES = {
|
|
747
|
+
LOGIN_SUCCESS: "Login successful",
|
|
748
|
+
ADMIN_LOGIN_SUCCESS: "Admin login successful",
|
|
749
|
+
LOGOUT_SUCCESS: "Logged out successfully",
|
|
750
|
+
REGISTER_SUCCESS: "User registered successfully",
|
|
751
|
+
TOKEN_REFRESH_SUCCESS: "Token refreshed successfully",
|
|
752
|
+
TWO_FA_SETUP_SUCCESS: "Two-factor authentication setup initiated",
|
|
753
|
+
TWO_FA_ENABLE_SUCCESS: "Two-factor authentication enabled",
|
|
754
|
+
TWO_FA_VERIFY_SUCCESS: "Two-factor authentication verified successfully",
|
|
755
|
+
TWO_FA_DISABLE_SUCCESS: "Two-factor authentication disabled"
|
|
756
|
+
};
|
|
757
|
+
|
|
735
758
|
// src/presentation/controller/AuthController.ts
|
|
736
759
|
var _AuthController = class _AuthController {
|
|
737
760
|
constructor(loginUseCase, adminLoginUseCase, logoutUseCase, registerUseCase, refreshTokenUseCase, twoFactorSetupUseCase, twoFactorEnableUseCase, twoFactorVerifyUseCase, twoFactorDisableUseCase) {
|
|
@@ -739,19 +762,13 @@ var _AuthController = class _AuthController {
|
|
|
739
762
|
try {
|
|
740
763
|
const loginDTO = req.body;
|
|
741
764
|
const result = await this.loginUseCase.execute(loginDTO);
|
|
742
|
-
const
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
},
|
|
750
|
-
{
|
|
751
|
-
status: "success"
|
|
752
|
-
}
|
|
753
|
-
);
|
|
754
|
-
res.status(200).json(response);
|
|
765
|
+
const loginData = {
|
|
766
|
+
accessToken: result.accessToken,
|
|
767
|
+
userId: result.id,
|
|
768
|
+
expiresAt: result.expiresAt,
|
|
769
|
+
enabled: result.enabled
|
|
770
|
+
};
|
|
771
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.LOGIN_SUCCESS, loginData);
|
|
755
772
|
} catch (error) {
|
|
756
773
|
next(error);
|
|
757
774
|
}
|
|
@@ -763,11 +780,7 @@ var _AuthController = class _AuthController {
|
|
|
763
780
|
throw new ForbiddenError("Admin password is required");
|
|
764
781
|
}
|
|
765
782
|
const result = await this.adminLoginUseCase.execute(loginDTO, adminPassword);
|
|
766
|
-
|
|
767
|
-
"Admin login successful",
|
|
768
|
-
result
|
|
769
|
-
);
|
|
770
|
-
res.status(201).json(response);
|
|
783
|
+
this.sendResponse(res, HTTP_STATUS.CREATED, MESSAGES.ADMIN_LOGIN_SUCCESS, result);
|
|
771
784
|
} catch (error) {
|
|
772
785
|
next(error);
|
|
773
786
|
}
|
|
@@ -775,8 +788,7 @@ var _AuthController = class _AuthController {
|
|
|
775
788
|
this.logout = /* @__PURE__ */ __name(async (req, res, next) => {
|
|
776
789
|
try {
|
|
777
790
|
await this.logoutUseCase.execute(req.body.id);
|
|
778
|
-
|
|
779
|
-
res.status(200).json(response);
|
|
791
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.LOGOUT_SUCCESS);
|
|
780
792
|
} catch (error) {
|
|
781
793
|
next(error);
|
|
782
794
|
}
|
|
@@ -785,12 +797,13 @@ var _AuthController = class _AuthController {
|
|
|
785
797
|
try {
|
|
786
798
|
const { email, name, password, role, adminPassword } = req.body;
|
|
787
799
|
await this.registerUseCase.execute(email, name, password, role, adminPassword);
|
|
788
|
-
|
|
789
|
-
|
|
800
|
+
this.sendResponse(
|
|
801
|
+
res,
|
|
802
|
+
HTTP_STATUS.OK,
|
|
803
|
+
MESSAGES.REGISTER_SUCCESS,
|
|
790
804
|
null,
|
|
791
|
-
{ status:
|
|
805
|
+
{ status: true }
|
|
792
806
|
);
|
|
793
|
-
res.status(200).json(response);
|
|
794
807
|
} catch (error) {
|
|
795
808
|
next(error);
|
|
796
809
|
}
|
|
@@ -799,11 +812,7 @@ var _AuthController = class _AuthController {
|
|
|
799
812
|
try {
|
|
800
813
|
const { refreshToken } = req.body;
|
|
801
814
|
const result = await this.refreshTokenUseCase.execute(refreshToken);
|
|
802
|
-
|
|
803
|
-
"Token refreshed successfully",
|
|
804
|
-
result
|
|
805
|
-
);
|
|
806
|
-
res.json(response);
|
|
815
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.TOKEN_REFRESH_SUCCESS, result);
|
|
807
816
|
} catch (error) {
|
|
808
817
|
next(error);
|
|
809
818
|
}
|
|
@@ -814,18 +823,15 @@ var _AuthController = class _AuthController {
|
|
|
814
823
|
throw new ForbiddenError("User authentication required");
|
|
815
824
|
}
|
|
816
825
|
const result = await this.twoFactorSetupUseCase.execute(req.auth.id);
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
);
|
|
828
|
-
res.status(200).json(response);
|
|
826
|
+
const setupData = {
|
|
827
|
+
qrCode: result.qrCodeUrl,
|
|
828
|
+
auth: this.createAuthData(true, false, AUTH_STATUS.NEEDS_SETUP)
|
|
829
|
+
};
|
|
830
|
+
const meta = {
|
|
831
|
+
nextStep: "Scan the QR code and enter your first code to verify",
|
|
832
|
+
redirectTo: "/2fa-enable"
|
|
833
|
+
};
|
|
834
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.TWO_FA_SETUP_SUCCESS, setupData, meta);
|
|
829
835
|
} catch (error) {
|
|
830
836
|
next(error);
|
|
831
837
|
}
|
|
@@ -834,19 +840,16 @@ var _AuthController = class _AuthController {
|
|
|
834
840
|
try {
|
|
835
841
|
const dto = { ...req.body, userId: req.auth?.id };
|
|
836
842
|
await this.twoFactorEnableUseCase.execute(dto);
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
);
|
|
849
|
-
res.status(200).json(response);
|
|
843
|
+
const enableData = {
|
|
844
|
+
isEnabled: true,
|
|
845
|
+
enabledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
846
|
+
auth: this.createAuthData(true, true, AUTH_STATUS.PENDING_VERIFICATION)
|
|
847
|
+
};
|
|
848
|
+
const meta = {
|
|
849
|
+
nextStep: "Proceed to verify with a valid 2FA token",
|
|
850
|
+
redirectTo: "/verify-2fa"
|
|
851
|
+
};
|
|
852
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.TWO_FA_ENABLE_SUCCESS, enableData, meta);
|
|
850
853
|
} catch (error) {
|
|
851
854
|
next(error);
|
|
852
855
|
}
|
|
@@ -855,25 +858,22 @@ var _AuthController = class _AuthController {
|
|
|
855
858
|
try {
|
|
856
859
|
const dto = req.body;
|
|
857
860
|
const result = await this.twoFactorVerifyUseCase.execute(dto);
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
name: result?.data?.name,
|
|
867
|
-
role: result?.data?.role
|
|
868
|
-
},
|
|
869
|
-
auth: this.createAuthData(true, true, "full_auth", true)
|
|
861
|
+
const verifyData = {
|
|
862
|
+
token: result?.token,
|
|
863
|
+
refreshToken: result?.refreshToken,
|
|
864
|
+
user: {
|
|
865
|
+
id: result?.data?.id,
|
|
866
|
+
email: result?.data?.email,
|
|
867
|
+
name: result?.data?.name,
|
|
868
|
+
role: result?.data?.role
|
|
870
869
|
},
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
870
|
+
auth: this.createAuthData(true, true, AUTH_STATUS.FULL_AUTH, true)
|
|
871
|
+
};
|
|
872
|
+
const meta = {
|
|
873
|
+
recommendation: "You're fully authenticated",
|
|
874
|
+
redirectTo: "/"
|
|
875
|
+
};
|
|
876
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.TWO_FA_VERIFY_SUCCESS, verifyData, meta);
|
|
877
877
|
} catch (error) {
|
|
878
878
|
next(error);
|
|
879
879
|
}
|
|
@@ -883,18 +883,15 @@ var _AuthController = class _AuthController {
|
|
|
883
883
|
const userId = req.auth.id;
|
|
884
884
|
const dto = req.body;
|
|
885
885
|
await this.twoFactorDisableUseCase.execute(userId, dto);
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
}
|
|
896
|
-
);
|
|
897
|
-
res.status(200).json(response);
|
|
886
|
+
const disableData = {
|
|
887
|
+
disabledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
888
|
+
auth: this.createAuthData(true, false, AUTH_STATUS.BASIC_AUTH, false)
|
|
889
|
+
};
|
|
890
|
+
const meta = {
|
|
891
|
+
securityNote: "Account now relies only on password. Re-enable 2FA for better security.",
|
|
892
|
+
redirectTo: "/login"
|
|
893
|
+
};
|
|
894
|
+
this.sendResponse(res, HTTP_STATUS.OK, MESSAGES.TWO_FA_DISABLE_SUCCESS, disableData, meta);
|
|
898
895
|
} catch (error) {
|
|
899
896
|
next(error);
|
|
900
897
|
}
|
|
@@ -909,7 +906,7 @@ var _AuthController = class _AuthController {
|
|
|
909
906
|
this.twoFactorVerifyUseCase = twoFactorVerifyUseCase;
|
|
910
907
|
this.twoFactorDisableUseCase = twoFactorDisableUseCase;
|
|
911
908
|
}
|
|
912
|
-
|
|
909
|
+
createResponse(message, data, meta) {
|
|
913
910
|
return {
|
|
914
911
|
success: true,
|
|
915
912
|
message,
|
|
@@ -928,6 +925,10 @@ var _AuthController = class _AuthController {
|
|
|
928
925
|
...verified !== void 0 && { verified }
|
|
929
926
|
};
|
|
930
927
|
}
|
|
928
|
+
sendResponse(res, statusCode, message, data, meta) {
|
|
929
|
+
const response = this.createResponse(message, data, meta);
|
|
930
|
+
res.status(statusCode).json(response);
|
|
931
|
+
}
|
|
931
932
|
};
|
|
932
933
|
__name(_AuthController, "AuthController");
|
|
933
934
|
var AuthController = _AuthController;
|