cca-auth-module 0.1.82 → 0.1.84
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/domain/interfaces/ApiResponse.d.ts +18 -0
- package/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +83 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -66
- package/dist/index.mjs.map +1 -1
- package/dist/presentation/controller/AuthController.d.ts +7 -5
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -704,16 +704,19 @@ var _AuthController = class _AuthController {
|
|
|
704
704
|
try {
|
|
705
705
|
const loginDTO = req.body;
|
|
706
706
|
const result = await this.loginUseCase.execute(loginDTO);
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
data: {
|
|
707
|
+
const response = this.createSuccessResponse(
|
|
708
|
+
"Login successful",
|
|
709
|
+
{
|
|
711
710
|
accessToken: result.accessToken,
|
|
712
711
|
userId: result.id,
|
|
713
712
|
expiresAt: result.expiresAt,
|
|
714
713
|
enabled: result.enabled
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
status: "success"
|
|
715
717
|
}
|
|
716
|
-
|
|
718
|
+
);
|
|
719
|
+
res.status(200).json(response);
|
|
717
720
|
} catch (error) {
|
|
718
721
|
next(error);
|
|
719
722
|
}
|
|
@@ -725,7 +728,11 @@ var _AuthController = class _AuthController {
|
|
|
725
728
|
throw new ForbiddenError("Admin password is required");
|
|
726
729
|
}
|
|
727
730
|
const result = await this.adminLoginUseCase.execute(loginDTO, adminPassword);
|
|
728
|
-
|
|
731
|
+
const response = this.createSuccessResponse(
|
|
732
|
+
"Admin login successful",
|
|
733
|
+
result
|
|
734
|
+
);
|
|
735
|
+
res.status(201).json(response);
|
|
729
736
|
} catch (error) {
|
|
730
737
|
next(error);
|
|
731
738
|
}
|
|
@@ -733,10 +740,8 @@ var _AuthController = class _AuthController {
|
|
|
733
740
|
this.logout = /* @__PURE__ */ __name(async (req, res, next) => {
|
|
734
741
|
try {
|
|
735
742
|
await this.logoutUseCase.execute(req.body.id);
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
message: "Logged out successfully"
|
|
739
|
-
});
|
|
743
|
+
const response = this.createSuccessResponse("Logged out successfully");
|
|
744
|
+
res.status(200).json(response);
|
|
740
745
|
} catch (error) {
|
|
741
746
|
next(error);
|
|
742
747
|
}
|
|
@@ -745,37 +750,47 @@ var _AuthController = class _AuthController {
|
|
|
745
750
|
try {
|
|
746
751
|
const { email, name, password, role, adminPassword } = req.body;
|
|
747
752
|
await this.registerUseCase.execute(email, name, password, role, adminPassword);
|
|
748
|
-
|
|
753
|
+
const response = this.createSuccessResponse(
|
|
754
|
+
"User registered successfully",
|
|
755
|
+
null,
|
|
756
|
+
{ status: "success" }
|
|
757
|
+
);
|
|
758
|
+
res.status(200).json(response);
|
|
749
759
|
} catch (error) {
|
|
750
760
|
next(error);
|
|
751
761
|
}
|
|
752
762
|
}, "register");
|
|
753
|
-
this.refreshToken = /* @__PURE__ */ __name(async (req, res) => {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
763
|
+
this.refreshToken = /* @__PURE__ */ __name(async (req, res, next) => {
|
|
764
|
+
try {
|
|
765
|
+
const { refreshToken } = req.body;
|
|
766
|
+
const result = await this.refreshTokenUseCase.execute(refreshToken);
|
|
767
|
+
const response = this.createSuccessResponse(
|
|
768
|
+
"Token refreshed successfully",
|
|
769
|
+
result
|
|
770
|
+
);
|
|
771
|
+
res.json(response);
|
|
772
|
+
} catch (error) {
|
|
773
|
+
next(error);
|
|
774
|
+
}
|
|
757
775
|
}, "refreshToken");
|
|
758
776
|
this.setup2FA = /* @__PURE__ */ __name(async (req, res, next) => {
|
|
759
777
|
try {
|
|
760
|
-
if (!req.auth?.id)
|
|
778
|
+
if (!req.auth?.id) {
|
|
779
|
+
throw new ForbiddenError("User authentication required");
|
|
780
|
+
}
|
|
761
781
|
const result = await this.twoFactorSetupUseCase.execute(req.auth.id);
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
data: {
|
|
782
|
+
const response = this.createSuccessResponse(
|
|
783
|
+
"Two-factor authentication setup initiated",
|
|
784
|
+
{
|
|
766
785
|
qrCode: result.qrCodeUrl,
|
|
767
|
-
auth:
|
|
768
|
-
hasAccessToken: true,
|
|
769
|
-
enable: false,
|
|
770
|
-
status: "needs_setup"
|
|
771
|
-
}
|
|
786
|
+
auth: this.createAuthData(true, false, "needs_setup")
|
|
772
787
|
},
|
|
773
|
-
|
|
774
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
788
|
+
{
|
|
775
789
|
nextStep: "Scan the QR code and enter your first code to verify",
|
|
776
790
|
redirectTo: "/2fa-setup"
|
|
777
791
|
}
|
|
778
|
-
|
|
792
|
+
);
|
|
793
|
+
res.status(200).json(response);
|
|
779
794
|
} catch (error) {
|
|
780
795
|
next(error);
|
|
781
796
|
}
|
|
@@ -784,24 +799,19 @@ var _AuthController = class _AuthController {
|
|
|
784
799
|
try {
|
|
785
800
|
const dto = { ...req.body, userId: req.auth?.id };
|
|
786
801
|
await this.twoFactorEnableUseCase.execute(dto);
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
data: {
|
|
802
|
+
const response = this.createSuccessResponse(
|
|
803
|
+
"Two-factor authentication enabled",
|
|
804
|
+
{
|
|
791
805
|
isEnabled: true,
|
|
792
806
|
enabledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
793
|
-
auth:
|
|
794
|
-
hasAccessToken: true,
|
|
795
|
-
enable: true,
|
|
796
|
-
status: "pending_verification"
|
|
797
|
-
}
|
|
807
|
+
auth: this.createAuthData(true, true, "pending_verification")
|
|
798
808
|
},
|
|
799
|
-
|
|
800
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
809
|
+
{
|
|
801
810
|
nextStep: "Proceed to verify with a valid 2FA token",
|
|
802
811
|
redirectTo: "/verify-2fa"
|
|
803
812
|
}
|
|
804
|
-
|
|
813
|
+
);
|
|
814
|
+
res.status(200).json(response);
|
|
805
815
|
} catch (error) {
|
|
806
816
|
next(error);
|
|
807
817
|
}
|
|
@@ -810,10 +820,9 @@ var _AuthController = class _AuthController {
|
|
|
810
820
|
try {
|
|
811
821
|
const dto = req.body;
|
|
812
822
|
const result = await this.twoFactorVerifyUseCase.execute(dto);
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
data: {
|
|
823
|
+
const response = this.createSuccessResponse(
|
|
824
|
+
"Two-factor authentication verified successfully",
|
|
825
|
+
{
|
|
817
826
|
token: result?.token,
|
|
818
827
|
refreshToken: result?.refreshToken,
|
|
819
828
|
user: {
|
|
@@ -822,19 +831,14 @@ var _AuthController = class _AuthController {
|
|
|
822
831
|
name: result?.data?.name,
|
|
823
832
|
role: result?.data?.role
|
|
824
833
|
},
|
|
825
|
-
auth:
|
|
826
|
-
hasAccessToken: true,
|
|
827
|
-
enable: true,
|
|
828
|
-
verified: true,
|
|
829
|
-
status: "full_auth"
|
|
830
|
-
}
|
|
834
|
+
auth: this.createAuthData(true, true, "full_auth", true)
|
|
831
835
|
},
|
|
832
|
-
|
|
833
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
836
|
+
{
|
|
834
837
|
recommendation: "You're fully authenticated",
|
|
835
838
|
redirectTo: "/"
|
|
836
839
|
}
|
|
837
|
-
|
|
840
|
+
);
|
|
841
|
+
res.status(200).json(response);
|
|
838
842
|
} catch (error) {
|
|
839
843
|
next(error);
|
|
840
844
|
}
|
|
@@ -844,24 +848,18 @@ var _AuthController = class _AuthController {
|
|
|
844
848
|
const userId = req.auth.id;
|
|
845
849
|
const dto = req.body;
|
|
846
850
|
await this.twoFactorDisableUseCase.execute(userId, dto);
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
data: {
|
|
851
|
+
const response = this.createSuccessResponse(
|
|
852
|
+
"Two-factor authentication disabled",
|
|
853
|
+
{
|
|
851
854
|
disabledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
852
|
-
auth:
|
|
853
|
-
hasAccessToken: true,
|
|
854
|
-
enable: false,
|
|
855
|
-
verified: false,
|
|
856
|
-
status: "basic_auth"
|
|
857
|
-
}
|
|
855
|
+
auth: this.createAuthData(true, false, "basic_auth", false)
|
|
858
856
|
},
|
|
859
|
-
|
|
860
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
857
|
+
{
|
|
861
858
|
securityNote: "Account now relies only on password. Re-enable 2FA for better security.",
|
|
862
859
|
redirectTo: "/login"
|
|
863
860
|
}
|
|
864
|
-
|
|
861
|
+
);
|
|
862
|
+
res.status(200).json(response);
|
|
865
863
|
} catch (error) {
|
|
866
864
|
next(error);
|
|
867
865
|
}
|
|
@@ -876,6 +874,25 @@ var _AuthController = class _AuthController {
|
|
|
876
874
|
this.twoFactorVerifyUseCase = twoFactorVerifyUseCase;
|
|
877
875
|
this.twoFactorDisableUseCase = twoFactorDisableUseCase;
|
|
878
876
|
}
|
|
877
|
+
createSuccessResponse(message, data, meta) {
|
|
878
|
+
return {
|
|
879
|
+
success: true,
|
|
880
|
+
message,
|
|
881
|
+
data,
|
|
882
|
+
meta: {
|
|
883
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
884
|
+
...meta
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
createAuthData(hasAccessToken, enable, status, verified) {
|
|
889
|
+
return {
|
|
890
|
+
hasAccessToken,
|
|
891
|
+
enable,
|
|
892
|
+
status,
|
|
893
|
+
...verified !== void 0 && { verified }
|
|
894
|
+
};
|
|
895
|
+
}
|
|
879
896
|
};
|
|
880
897
|
__name(_AuthController, "AuthController");
|
|
881
898
|
var AuthController = _AuthController;
|