@ciscode/authentication-kit 1.4.2 → 1.5.0

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.
@@ -14,6 +14,7 @@ export declare class AuthController {
14
14
  constructor(auth: AuthService, oauth: OAuthService);
15
15
  register(dto: RegisterDto, res: Response): Promise<Response<any, Record<string, any>>>;
16
16
  verifyEmail(dto: VerifyEmailDto, res: Response): Promise<Response<any, Record<string, any>>>;
17
+ verifyEmailGet(token: string, res: Response): Promise<void>;
17
18
  resendVerification(dto: ResendVerificationDto, res: Response): Promise<Response<any, Record<string, any>>>;
18
19
  login(dto: LoginDto, res: Response): Promise<Response<any, Record<string, any>>>;
19
20
  refresh(dto: RefreshTokenDto, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
@@ -42,6 +42,20 @@ let AuthController = class AuthController {
42
42
  const result = await this.auth.verifyEmail(dto.token);
43
43
  return res.status(200).json(result);
44
44
  }
45
+ async verifyEmailGet(token, res) {
46
+ try {
47
+ const result = await this.auth.verifyEmail(token);
48
+ // Redirect to frontend with success
49
+ const frontendUrl = process.env.FRONTEND_URL || 'http://localhost:3000';
50
+ return res.redirect(`${frontendUrl}/email-verified?success=true&message=${encodeURIComponent(result.message)}`);
51
+ }
52
+ catch (error) {
53
+ // Redirect to frontend with error
54
+ const frontendUrl = process.env.FRONTEND_URL || 'http://localhost:3000';
55
+ const errorMsg = error.message || 'Email verification failed';
56
+ return res.redirect(`${frontendUrl}/email-verified?success=false&message=${encodeURIComponent(errorMsg)}`);
57
+ }
58
+ }
45
59
  async resendVerification(dto, res) {
46
60
  const result = await this.auth.resendVerification(dto.email);
47
61
  return res.status(200).json(result);
@@ -169,6 +183,14 @@ __decorate([
169
183
  __metadata("design:paramtypes", [verify_email_dto_1.VerifyEmailDto, Object]),
170
184
  __metadata("design:returntype", Promise)
171
185
  ], AuthController.prototype, "verifyEmail", null);
186
+ __decorate([
187
+ (0, common_1.Get)('verify-email/:token'),
188
+ __param(0, (0, common_1.Param)('token')),
189
+ __param(1, (0, common_1.Res)()),
190
+ __metadata("design:type", Function),
191
+ __metadata("design:paramtypes", [String, Object]),
192
+ __metadata("design:returntype", Promise)
193
+ ], AuthController.prototype, "verifyEmailGet", null);
172
194
  __decorate([
173
195
  (0, common_1.Post)('resend-verification'),
174
196
  __param(0, (0, common_1.Body)()),
@@ -64,13 +64,18 @@ let MailService = class MailService {
64
64
  }
65
65
  }
66
66
  async sendVerificationEmail(email, token) {
67
+ var _a;
67
68
  if (!this.smtpConfigured) {
68
69
  const error = new common_1.InternalServerErrorException('SMTP not configured - cannot send emails');
69
70
  this.logger.error('Attempted to send email but SMTP is not configured', '', 'MailService');
70
71
  throw error;
71
72
  }
72
73
  try {
73
- const url = `${process.env.FRONTEND_URL}/confirm-email?token=${token}`;
74
+ // Option 1: Link to frontend (frontend must call POST /api/auth/verify-email)
75
+ // const url = `${process.env.FRONTEND_URL}/confirm-email?token=${token}`;
76
+ // Option 2: Link directly to backend API (backend verifies and redirects)
77
+ const backendUrl = process.env.BACKEND_URL || ((_a = process.env.FRONTEND_URL) === null || _a === void 0 ? void 0 : _a.replace(/:\d+$/, ':3000')) || 'http://localhost:3000';
78
+ const url = `${backendUrl}/api/auth/verify-email/${token}`;
74
79
  await this.transporter.sendMail({
75
80
  from: process.env.FROM_EMAIL,
76
81
  to: email,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciscode/authentication-kit",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "NestJS auth kit with local + OAuth, JWT, RBAC, password reset.",
5
5
  "publishConfig": {
6
6
  "access": "public"