hazo_auth 1.4.2 → 1.6.1
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/README.md +65 -19
- package/SETUP_CHECKLIST.md +779 -0
- package/dist/app/api/hazo_auth/change_password/route.d.ts +8 -0
- package/dist/app/api/hazo_auth/change_password/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/change_password/route.js +98 -0
- package/dist/app/api/hazo_auth/forgot_password/route.d.ts +8 -0
- package/dist/app/api/hazo_auth/forgot_password/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/forgot_password/route.js +78 -0
- package/dist/app/api/hazo_auth/get_auth/route.d.ts +10 -0
- package/dist/app/api/hazo_auth/get_auth/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/get_auth/route.js +63 -0
- package/dist/app/api/hazo_auth/invalidate_cache/route.d.ts +14 -0
- package/dist/app/api/hazo_auth/invalidate_cache/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/invalidate_cache/route.js +96 -0
- package/dist/app/api/hazo_auth/library_photo/[category]/[filename]/route.d.ts +9 -0
- package/dist/app/api/hazo_auth/library_photo/[category]/[filename]/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/library_photo/[category]/[filename]/route.js +82 -0
- package/dist/app/api/hazo_auth/library_photos/route.d.ts +22 -0
- package/dist/app/api/hazo_auth/library_photos/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/library_photos/route.js +80 -0
- package/dist/app/api/hazo_auth/login/route.d.ts +12 -0
- package/dist/app/api/hazo_auth/login/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/login/route.js +140 -0
- package/dist/app/api/hazo_auth/logout/route.d.ts +8 -0
- package/dist/app/api/hazo_auth/logout/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/logout/route.js +71 -0
- package/dist/app/api/hazo_auth/me/route.d.ts +3 -0
- package/dist/app/api/hazo_auth/me/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/me/route.js +34 -0
- package/dist/app/api/hazo_auth/profile_picture/[filename]/route.d.ts +7 -0
- package/dist/app/api/hazo_auth/profile_picture/[filename]/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/profile_picture/[filename]/route.js +43 -0
- package/dist/app/api/hazo_auth/register/route.d.ts +9 -0
- package/dist/app/api/hazo_auth/register/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/register/route.js +80 -0
- package/dist/app/api/hazo_auth/remove_profile_picture/route.d.ts +8 -0
- package/dist/app/api/hazo_auth/remove_profile_picture/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/remove_profile_picture/route.js +64 -0
- package/dist/app/api/hazo_auth/resend_verification/route.d.ts +8 -0
- package/dist/app/api/hazo_auth/resend_verification/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/resend_verification/route.js +79 -0
- package/dist/app/api/hazo_auth/reset_password/route.d.ts +8 -0
- package/dist/app/api/hazo_auth/reset_password/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/reset_password/route.js +76 -0
- package/dist/app/api/hazo_auth/update_user/route.d.ts +9 -0
- package/dist/app/api/hazo_auth/update_user/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/update_user/route.js +95 -0
- package/dist/app/api/hazo_auth/upload_profile_picture/route.d.ts +9 -0
- package/dist/app/api/hazo_auth/upload_profile_picture/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/upload_profile_picture/route.js +204 -0
- package/dist/app/api/hazo_auth/validate_reset_token/route.d.ts +6 -0
- package/dist/app/api/hazo_auth/validate_reset_token/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/validate_reset_token/route.js +58 -0
- package/dist/app/api/hazo_auth/verify_email/route.d.ts +11 -0
- package/dist/app/api/hazo_auth/verify_email/route.d.ts.map +1 -0
- package/dist/app/api/hazo_auth/verify_email/route.js +63 -0
- package/dist/cli/generate.d.ts +7 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/cli/generate.js +184 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +173 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +201 -0
- package/dist/cli/validate.d.ts +15 -0
- package/dist/cli/validate.d.ts.map +1 -0
- package/dist/cli/validate.js +509 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +45 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -1
- package/dist/hooks/use-mobile.js +17 -3
- package/dist/lib/services/profile_picture_service.d.ts +34 -2
- package/dist/lib/services/profile_picture_service.d.ts.map +1 -1
- package/dist/lib/services/profile_picture_service.js +157 -15
- package/dist/page_components/forgot_password.d.ts +19 -0
- package/dist/page_components/forgot_password.d.ts.map +1 -0
- package/dist/page_components/forgot_password.js +36 -0
- package/dist/page_components/index.d.ts +7 -0
- package/dist/page_components/index.d.ts.map +1 -0
- package/dist/page_components/index.js +9 -0
- package/dist/page_components/login.d.ts +26 -0
- package/dist/page_components/login.d.ts.map +1 -0
- package/dist/page_components/login.js +40 -0
- package/dist/page_components/my_settings.d.ts +64 -0
- package/dist/page_components/my_settings.d.ts.map +1 -0
- package/dist/page_components/my_settings.js +67 -0
- package/dist/page_components/register.d.ts +25 -0
- package/dist/page_components/register.d.ts.map +1 -0
- package/dist/page_components/register.js +43 -0
- package/dist/page_components/reset_password.d.ts +25 -0
- package/dist/page_components/reset_password.d.ts.map +1 -0
- package/dist/page_components/reset_password.js +43 -0
- package/dist/page_components/verify_email.d.ts +21 -0
- package/dist/page_components/verify_email.d.ts.map +1 -0
- package/dist/page_components/verify_email.js +36 -0
- package/dist/server/routes/change_password.d.ts +2 -0
- package/dist/server/routes/change_password.d.ts.map +1 -0
- package/dist/server/routes/change_password.js +2 -0
- package/dist/server/routes/forgot_password.d.ts +2 -0
- package/dist/server/routes/forgot_password.d.ts.map +1 -0
- package/dist/server/routes/forgot_password.js +2 -0
- package/dist/server/routes/get_auth.d.ts +2 -0
- package/dist/server/routes/get_auth.d.ts.map +1 -0
- package/dist/server/routes/get_auth.js +2 -0
- package/dist/server/routes/index.d.ts +19 -0
- package/dist/server/routes/index.d.ts.map +1 -0
- package/dist/server/routes/index.js +25 -0
- package/dist/server/routes/invalidate_cache.d.ts +2 -0
- package/dist/server/routes/invalidate_cache.d.ts.map +1 -0
- package/dist/server/routes/invalidate_cache.js +2 -0
- package/dist/server/routes/library_photo.d.ts +2 -0
- package/dist/server/routes/library_photo.d.ts.map +1 -0
- package/dist/server/routes/library_photo.js +3 -0
- package/dist/server/routes/library_photos.d.ts +2 -0
- package/dist/server/routes/library_photos.d.ts.map +1 -0
- package/dist/server/routes/library_photos.js +2 -0
- package/dist/server/routes/login.d.ts +2 -0
- package/dist/server/routes/login.d.ts.map +1 -0
- package/dist/server/routes/login.js +2 -0
- package/dist/server/routes/logout.d.ts +2 -0
- package/dist/server/routes/logout.d.ts.map +1 -0
- package/dist/server/routes/logout.js +2 -0
- package/dist/server/routes/me.d.ts +2 -0
- package/dist/server/routes/me.d.ts.map +1 -0
- package/dist/server/routes/me.js +2 -0
- package/dist/server/routes/profile_picture_filename.d.ts +2 -0
- package/dist/server/routes/profile_picture_filename.d.ts.map +1 -0
- package/dist/server/routes/profile_picture_filename.js +3 -0
- package/dist/server/routes/register.d.ts +2 -0
- package/dist/server/routes/register.d.ts.map +1 -0
- package/dist/server/routes/register.js +2 -0
- package/dist/server/routes/remove_profile_picture.d.ts +2 -0
- package/dist/server/routes/remove_profile_picture.d.ts.map +1 -0
- package/dist/server/routes/remove_profile_picture.js +2 -0
- package/dist/server/routes/resend_verification.d.ts +2 -0
- package/dist/server/routes/resend_verification.d.ts.map +1 -0
- package/dist/server/routes/resend_verification.js +2 -0
- package/dist/server/routes/reset_password.d.ts +2 -0
- package/dist/server/routes/reset_password.d.ts.map +1 -0
- package/dist/server/routes/reset_password.js +2 -0
- package/dist/server/routes/update_user.d.ts +2 -0
- package/dist/server/routes/update_user.d.ts.map +1 -0
- package/dist/server/routes/update_user.js +2 -0
- package/dist/server/routes/upload_profile_picture.d.ts +2 -0
- package/dist/server/routes/upload_profile_picture.d.ts.map +1 -0
- package/dist/server/routes/upload_profile_picture.js +2 -0
- package/dist/server/routes/validate_reset_token.d.ts +2 -0
- package/dist/server/routes/validate_reset_token.d.ts.map +1 -0
- package/dist/server/routes/validate_reset_token.js +2 -0
- package/dist/server/routes/verify_email.d.ts +2 -0
- package/dist/server/routes/verify_email.d.ts.map +1 -0
- package/dist/server/routes/verify_email.js +2 -0
- package/package.json +40 -17
- package/components.json +0 -22
- package/instrumentation.ts +0 -32
- package/migrations/001_add_token_type_to_refresh_tokens.sql +0 -14
- package/migrations/002_add_name_to_hazo_users.sql +0 -7
- package/migrations/003_add_url_on_logon_to_hazo_users.sql +0 -8
- package/next.config.mjs +0 -67
- package/postcss.config.mjs +0 -8
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/next.svg +0 -1
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/scripts/apply_migration.ts +0 -118
- package/scripts/init_users.ts +0 -378
- package/src/app/api/hazo_auth/auth/upload_profile_picture/route.ts +0 -268
- package/src/app/api/hazo_auth/change_password/route.ts +0 -132
- package/src/app/api/hazo_auth/forgot_password/route.ts +0 -107
- package/src/app/api/hazo_auth/get_auth/route.ts +0 -89
- package/src/app/api/hazo_auth/invalidate_cache/route.ts +0 -139
- package/src/app/api/hazo_auth/library_photos/route.ts +0 -73
- package/src/app/api/hazo_auth/login/route.ts +0 -181
- package/src/app/api/hazo_auth/logout/route.ts +0 -89
- package/src/app/api/hazo_auth/me/route.ts +0 -47
- package/src/app/api/hazo_auth/profile_picture/[filename]/route.ts +0 -67
- package/src/app/api/hazo_auth/register/route.ts +0 -109
- package/src/app/api/hazo_auth/remove_profile_picture/route.ts +0 -86
- package/src/app/api/hazo_auth/resend_verification/route.ts +0 -108
- package/src/app/api/hazo_auth/reset_password/route.ts +0 -107
- package/src/app/api/hazo_auth/update_user/route.ts +0 -126
- package/src/app/api/hazo_auth/upload_profile_picture/route.ts +0 -268
- package/src/app/api/hazo_auth/user_management/permissions/route.ts +0 -367
- package/src/app/api/hazo_auth/user_management/roles/route.ts +0 -442
- package/src/app/api/hazo_auth/user_management/users/roles/route.ts +0 -367
- package/src/app/api/hazo_auth/user_management/users/route.ts +0 -239
- package/src/app/api/hazo_auth/validate_reset_token/route.ts +0 -83
- package/src/app/api/hazo_auth/verify_email/route.ts +0 -88
- package/src/app/api/migrations/apply/route.ts +0 -91
- package/src/app/favicon.ico +0 -0
- package/src/app/fonts/GeistMonoVF.woff +0 -0
- package/src/app/fonts/GeistVF.woff +0 -0
- package/src/app/globals.css +0 -89
- package/src/app/hazo_auth/forgot_password/forgot_password_page_client.tsx +0 -60
- package/src/app/hazo_auth/forgot_password/page.tsx +0 -24
- package/src/app/hazo_auth/login/login_page_client.tsx +0 -86
- package/src/app/hazo_auth/login/page.tsx +0 -38
- package/src/app/hazo_auth/my_settings/my_settings_page_client.tsx +0 -120
- package/src/app/hazo_auth/my_settings/page.tsx +0 -40
- package/src/app/hazo_auth/register/page.tsx +0 -36
- package/src/app/hazo_auth/register/register_page_client.tsx +0 -81
- package/src/app/hazo_auth/reset_password/page.tsx +0 -29
- package/src/app/hazo_auth/reset_password/reset_password_page_client.tsx +0 -81
- package/src/app/hazo_auth/user_management/page.tsx +0 -14
- package/src/app/hazo_auth/user_management/user_management_page_client.tsx +0 -16
- package/src/app/hazo_auth/verify_email/page.tsx +0 -24
- package/src/app/hazo_auth/verify_email/verify_email_page_client.tsx +0 -60
- package/src/app/hazo_connect/api/sqlite/data/route.ts +0 -203
- package/src/app/hazo_connect/api/sqlite/schema/route.ts +0 -45
- package/src/app/hazo_connect/api/sqlite/tables/route.ts +0 -36
- package/src/app/hazo_connect/sqlite_admin/page.tsx +0 -51
- package/src/app/hazo_connect/sqlite_admin/sqlite-admin-client.tsx +0 -984
- package/src/app/layout.tsx +0 -43
- package/src/app/page.tsx +0 -170
- package/src/components/index.ts +0 -7
- package/src/components/layouts/email_verification/config/email_verification_field_config.ts +0 -86
- package/src/components/layouts/email_verification/hooks/use_email_verification.ts +0 -297
- package/src/components/layouts/email_verification/index.tsx +0 -297
- package/src/components/layouts/forgot_password/config/forgot_password_field_config.ts +0 -58
- package/src/components/layouts/forgot_password/hooks/use_forgot_password_form.ts +0 -179
- package/src/components/layouts/forgot_password/index.tsx +0 -168
- package/src/components/layouts/index.ts +0 -26
- package/src/components/layouts/login/config/login_field_config.ts +0 -67
- package/src/components/layouts/login/hooks/use_login_form.ts +0 -286
- package/src/components/layouts/login/index.tsx +0 -252
- package/src/components/layouts/my_settings/components/editable_field.tsx +0 -177
- package/src/components/layouts/my_settings/components/password_change_dialog.tsx +0 -301
- package/src/components/layouts/my_settings/components/profile_picture_dialog.tsx +0 -385
- package/src/components/layouts/my_settings/components/profile_picture_display.tsx +0 -66
- package/src/components/layouts/my_settings/components/profile_picture_gravatar_tab.tsx +0 -143
- package/src/components/layouts/my_settings/components/profile_picture_library_tab.tsx +0 -311
- package/src/components/layouts/my_settings/components/profile_picture_upload_tab.tsx +0 -341
- package/src/components/layouts/my_settings/config/my_settings_field_config.ts +0 -61
- package/src/components/layouts/my_settings/hooks/use_my_settings.ts +0 -458
- package/src/components/layouts/my_settings/index.tsx +0 -351
- package/src/components/layouts/register/config/register_field_config.ts +0 -101
- package/src/components/layouts/register/hooks/use_register_form.ts +0 -275
- package/src/components/layouts/register/index.tsx +0 -226
- package/src/components/layouts/reset_password/config/reset_password_field_config.ts +0 -86
- package/src/components/layouts/reset_password/hooks/use_reset_password_form.ts +0 -276
- package/src/components/layouts/reset_password/index.tsx +0 -294
- package/src/components/layouts/shared/components/already_logged_in_guard.tsx +0 -95
- package/src/components/layouts/shared/components/auth_page_shell.tsx +0 -36
- package/src/components/layouts/shared/components/field_error_message.tsx +0 -29
- package/src/components/layouts/shared/components/form_action_buttons.tsx +0 -64
- package/src/components/layouts/shared/components/form_field_wrapper.tsx +0 -44
- package/src/components/layouts/shared/components/form_header.tsx +0 -36
- package/src/components/layouts/shared/components/logout_button.tsx +0 -76
- package/src/components/layouts/shared/components/password_field.tsx +0 -72
- package/src/components/layouts/shared/components/profile_pic_menu.tsx +0 -321
- package/src/components/layouts/shared/components/profile_pic_menu_wrapper.tsx +0 -40
- package/src/components/layouts/shared/components/sidebar_layout_wrapper.tsx +0 -214
- package/src/components/layouts/shared/components/standalone_layout_wrapper.tsx +0 -53
- package/src/components/layouts/shared/components/two_column_auth_layout.tsx +0 -44
- package/src/components/layouts/shared/components/unauthorized_guard.tsx +0 -78
- package/src/components/layouts/shared/components/visual_panel.tsx +0 -41
- package/src/components/layouts/shared/config/layout_customization.ts +0 -95
- package/src/components/layouts/shared/data/layout_data_client.ts +0 -19
- package/src/components/layouts/shared/hooks/use_auth_status.ts +0 -103
- package/src/components/layouts/shared/hooks/use_hazo_auth.ts +0 -158
- package/src/components/layouts/shared/index.ts +0 -34
- package/src/components/layouts/shared/utils/ip_address.ts +0 -37
- package/src/components/layouts/shared/utils/validation.ts +0 -66
- package/src/components/layouts/user_management/components/roles_matrix.tsx +0 -607
- package/src/components/layouts/user_management/index.tsx +0 -1295
- package/src/components/ui/alert-dialog.tsx +0 -141
- package/src/components/ui/avatar.tsx +0 -50
- package/src/components/ui/button.tsx +0 -57
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/dropdown-menu.tsx +0 -201
- package/src/components/ui/hazo_ui_tooltip.tsx +0 -67
- package/src/components/ui/index.ts +0 -22
- package/src/components/ui/input.tsx +0 -22
- package/src/components/ui/label.tsx +0 -26
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/sheet.tsx +0 -139
- package/src/components/ui/sidebar.tsx +0 -773
- package/src/components/ui/skeleton.tsx +0 -15
- package/src/components/ui/sonner.tsx +0 -31
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/table.tsx +0 -120
- package/src/components/ui/tabs.tsx +0 -55
- package/src/components/ui/tooltip.tsx +0 -32
- package/src/components/ui/vertical-tabs.tsx +0 -59
- package/src/hooks/use-mobile.tsx +0 -19
- package/src/index.ts +0 -7
- package/src/lib/already_logged_in_config.server.ts +0 -46
- package/src/lib/app_logger.ts +0 -24
- package/src/lib/auth/auth_cache.ts +0 -220
- package/src/lib/auth/auth_rate_limiter.ts +0 -121
- package/src/lib/auth/auth_types.ts +0 -65
- package/src/lib/auth/auth_utils.server.ts +0 -196
- package/src/lib/auth/hazo_get_auth.server.ts +0 -333
- package/src/lib/auth/index.ts +0 -23
- package/src/lib/auth/server_auth.ts +0 -88
- package/src/lib/auth_utility_config.server.ts +0 -136
- package/src/lib/config/config_loader.server.ts +0 -164
- package/src/lib/email_verification_config.server.ts +0 -32
- package/src/lib/file_types_config.server.ts +0 -25
- package/src/lib/forgot_password_config.server.ts +0 -32
- package/src/lib/hazo_connect_instance.server.ts +0 -101
- package/src/lib/hazo_connect_setup.server.ts +0 -194
- package/src/lib/hazo_connect_setup.ts +0 -54
- package/src/lib/index.ts +0 -44
- package/src/lib/login_config.server.ts +0 -71
- package/src/lib/messages_config.server.ts +0 -45
- package/src/lib/migrations/apply_migration.ts +0 -105
- package/src/lib/my_settings_config.server.ts +0 -135
- package/src/lib/password_requirements_config.server.ts +0 -39
- package/src/lib/profile_pic_menu_config.server.ts +0 -138
- package/src/lib/profile_picture_config.server.ts +0 -56
- package/src/lib/register_config.server.ts +0 -73
- package/src/lib/reset_password_config.server.ts +0 -75
- package/src/lib/services/email_service.ts +0 -581
- package/src/lib/services/email_verification_service.ts +0 -270
- package/src/lib/services/index.ts +0 -15
- package/src/lib/services/login_service.ts +0 -134
- package/src/lib/services/password_change_service.ts +0 -154
- package/src/lib/services/password_reset_service.ts +0 -405
- package/src/lib/services/profile_picture_remove_service.ts +0 -120
- package/src/lib/services/profile_picture_service.ts +0 -215
- package/src/lib/services/profile_picture_source_mapper.ts +0 -62
- package/src/lib/services/registration_service.ts +0 -184
- package/src/lib/services/token_service.ts +0 -240
- package/src/lib/services/user_profiles_service.ts +0 -143
- package/src/lib/services/user_update_service.ts +0 -141
- package/src/lib/ui_shell_config.server.ts +0 -73
- package/src/lib/ui_sizes_config.server.ts +0 -37
- package/src/lib/user_fields_config.server.ts +0 -31
- package/src/lib/user_management_config.server.ts +0 -39
- package/src/lib/utils/api_route_helpers.ts +0 -60
- package/src/lib/utils/error_sanitizer.ts +0 -75
- package/src/lib/utils.ts +0 -11
- package/src/middleware.ts +0 -94
- package/src/routes/index.ts +0 -34
- package/src/server/config/config_loader.ts +0 -496
- package/src/server/index.ts +0 -38
- package/src/server/logging/logger_service.ts +0 -56
- package/src/server/routes/root_router.ts +0 -16
- package/src/server/server.ts +0 -28
- package/src/server/types/app_types.ts +0 -74
- package/src/server/types/express.d.ts +0 -16
- package/src/stories/email_verification_layout.stories.tsx +0 -137
- package/src/stories/forgot_password_layout.stories.tsx +0 -85
- package/src/stories/login_layout.stories.tsx +0 -85
- package/src/stories/project_overview.stories.tsx +0 -33
- package/src/stories/register_layout.stories.tsx +0 -107
- package/tailwind.config.ts +0 -77
- package/tsconfig.build.json +0 -36
- package/tsconfig.json +0 -28
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// file_description: API route for resetting user password using a reset token
|
|
2
|
+
// section: imports
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { get_hazo_connect_instance } from "../../../../lib/hazo_connect_instance.server";
|
|
5
|
+
import { reset_password } from "../../../../lib/services/password_reset_service";
|
|
6
|
+
import { create_app_logger } from "../../../../lib/app_logger";
|
|
7
|
+
import { get_password_requirements_config } from "../../../../lib/password_requirements_config.server";
|
|
8
|
+
import { get_filename, get_line_number } from "../../../../lib/utils/api_route_helpers";
|
|
9
|
+
// section: api_handler
|
|
10
|
+
export async function POST(request) {
|
|
11
|
+
const logger = create_app_logger();
|
|
12
|
+
try {
|
|
13
|
+
const body = await request.json();
|
|
14
|
+
const { token, new_password } = body;
|
|
15
|
+
// Validate input
|
|
16
|
+
if (!token) {
|
|
17
|
+
logger.warn("password_reset_validation_failed", {
|
|
18
|
+
filename: get_filename(),
|
|
19
|
+
line_number: get_line_number(),
|
|
20
|
+
error: "Token is required",
|
|
21
|
+
});
|
|
22
|
+
return NextResponse.json({ error: "Token is required" }, { status: 400 });
|
|
23
|
+
}
|
|
24
|
+
if (!new_password) {
|
|
25
|
+
logger.warn("password_reset_validation_failed", {
|
|
26
|
+
filename: get_filename(),
|
|
27
|
+
line_number: get_line_number(),
|
|
28
|
+
error: "New password is required",
|
|
29
|
+
});
|
|
30
|
+
return NextResponse.json({ error: "New password is required" }, { status: 400 });
|
|
31
|
+
}
|
|
32
|
+
// Get singleton hazo_connect instance (reuses same connection across all routes)
|
|
33
|
+
const hazoConnect = get_hazo_connect_instance();
|
|
34
|
+
// Get password requirements from config
|
|
35
|
+
const passwordRequirements = get_password_requirements_config();
|
|
36
|
+
// Reset password using the password reset service
|
|
37
|
+
const result = await reset_password(hazoConnect, {
|
|
38
|
+
token,
|
|
39
|
+
new_password,
|
|
40
|
+
minimum_length: passwordRequirements.minimum_length,
|
|
41
|
+
});
|
|
42
|
+
if (!result.success) {
|
|
43
|
+
logger.warn("password_reset_failed", {
|
|
44
|
+
filename: get_filename(),
|
|
45
|
+
line_number: get_line_number(),
|
|
46
|
+
error: result.error,
|
|
47
|
+
});
|
|
48
|
+
return NextResponse.json({
|
|
49
|
+
success: false,
|
|
50
|
+
error: result.error || "Failed to reset password",
|
|
51
|
+
}, { status: 400 });
|
|
52
|
+
}
|
|
53
|
+
logger.info("password_reset_successful", {
|
|
54
|
+
filename: get_filename(),
|
|
55
|
+
line_number: get_line_number(),
|
|
56
|
+
user_id: result.user_id,
|
|
57
|
+
email: result.email,
|
|
58
|
+
});
|
|
59
|
+
return NextResponse.json({
|
|
60
|
+
success: true,
|
|
61
|
+
message: "Password has been reset successfully",
|
|
62
|
+
}, { status: 200 });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const error_message = error instanceof Error ? error.message : "Unknown error";
|
|
66
|
+
logger.error("password_reset_error", {
|
|
67
|
+
filename: get_filename(),
|
|
68
|
+
line_number: get_line_number(),
|
|
69
|
+
error: error_message,
|
|
70
|
+
});
|
|
71
|
+
return NextResponse.json({
|
|
72
|
+
success: false,
|
|
73
|
+
error: "An error occurred while resetting your password",
|
|
74
|
+
}, { status: 500 });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
export declare function PATCH(request: NextRequest): Promise<NextResponse<{
|
|
3
|
+
error: string;
|
|
4
|
+
}> | NextResponse<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
message: string;
|
|
7
|
+
email_changed: boolean | undefined;
|
|
8
|
+
}>>;
|
|
9
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/hazo_auth/update_user/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQxD,wBAAsB,KAAK,CAAC,OAAO,EAAE,WAAW;;;;;;IAkH/C"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// file_description: API route for updating user profile information
|
|
2
|
+
// section: imports
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { get_hazo_connect_instance } from "../../../../lib/hazo_connect_instance.server";
|
|
5
|
+
import { create_app_logger } from "../../../../lib/app_logger";
|
|
6
|
+
import { update_user_profile } from "../../../../lib/services/user_update_service";
|
|
7
|
+
import { get_filename, get_line_number } from "../../../../lib/utils/api_route_helpers";
|
|
8
|
+
import { require_auth } from "../../../../lib/auth/auth_utils.server";
|
|
9
|
+
// section: api_handler
|
|
10
|
+
export async function PATCH(request) {
|
|
11
|
+
const logger = create_app_logger();
|
|
12
|
+
try {
|
|
13
|
+
// Use centralized auth check
|
|
14
|
+
let user_id;
|
|
15
|
+
try {
|
|
16
|
+
const user = await require_auth(request);
|
|
17
|
+
user_id = user.user_id;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof Error && error.message === "Authentication required") {
|
|
21
|
+
logger.warn("user_update_authentication_failed", {
|
|
22
|
+
filename: get_filename(),
|
|
23
|
+
line_number: get_line_number(),
|
|
24
|
+
error: "User not authenticated",
|
|
25
|
+
});
|
|
26
|
+
return NextResponse.json({ error: "Authentication required" }, { status: 401 });
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const body = await request.json();
|
|
31
|
+
const { name, email, profile_picture_url, profile_source } = body;
|
|
32
|
+
// Validate input (at least one field must be provided)
|
|
33
|
+
if (name === undefined && email === undefined && profile_picture_url === undefined) {
|
|
34
|
+
logger.warn("user_update_validation_failed", {
|
|
35
|
+
filename: get_filename(),
|
|
36
|
+
line_number: get_line_number(),
|
|
37
|
+
error: "No fields to update",
|
|
38
|
+
});
|
|
39
|
+
return NextResponse.json({ error: "At least one field (name, email, or profile_picture_url) must be provided" }, { status: 400 });
|
|
40
|
+
}
|
|
41
|
+
// Get singleton hazo_connect instance
|
|
42
|
+
const hazoConnect = get_hazo_connect_instance();
|
|
43
|
+
// Update user profile
|
|
44
|
+
const result = await update_user_profile(hazoConnect, user_id, {
|
|
45
|
+
name,
|
|
46
|
+
email,
|
|
47
|
+
profile_picture_url,
|
|
48
|
+
profile_source,
|
|
49
|
+
});
|
|
50
|
+
if (!result.success) {
|
|
51
|
+
logger.warn("user_update_failed", {
|
|
52
|
+
filename: get_filename(),
|
|
53
|
+
line_number: get_line_number(),
|
|
54
|
+
error: result.error,
|
|
55
|
+
user_id,
|
|
56
|
+
email_changed: result.email_changed,
|
|
57
|
+
});
|
|
58
|
+
return NextResponse.json({ error: result.error || "Failed to update user profile" }, { status: 400 });
|
|
59
|
+
}
|
|
60
|
+
logger.info("user_update_successful", {
|
|
61
|
+
filename: get_filename(),
|
|
62
|
+
line_number: get_line_number(),
|
|
63
|
+
user_id,
|
|
64
|
+
email_changed: result.email_changed,
|
|
65
|
+
});
|
|
66
|
+
// Create response
|
|
67
|
+
const response = NextResponse.json({
|
|
68
|
+
success: true,
|
|
69
|
+
message: "Profile updated successfully",
|
|
70
|
+
email_changed: result.email_changed,
|
|
71
|
+
}, { status: 200 });
|
|
72
|
+
// If email changed, update the cookie (match login route cookie settings)
|
|
73
|
+
if (result.email_changed && email) {
|
|
74
|
+
response.cookies.set("hazo_auth_user_email", email, {
|
|
75
|
+
httpOnly: true,
|
|
76
|
+
secure: process.env.NODE_ENV === "production",
|
|
77
|
+
sameSite: "lax",
|
|
78
|
+
path: "/",
|
|
79
|
+
maxAge: 60 * 60 * 24 * 30, // 30 days
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const error_message = error instanceof Error ? error.message : "Unknown error";
|
|
86
|
+
const error_stack = error instanceof Error ? error.stack : undefined;
|
|
87
|
+
logger.error("user_update_error", {
|
|
88
|
+
filename: get_filename(),
|
|
89
|
+
line_number: get_line_number(),
|
|
90
|
+
error_message,
|
|
91
|
+
error_stack,
|
|
92
|
+
});
|
|
93
|
+
return NextResponse.json({ error: "Failed to update user profile. Please try again." }, { status: 500 });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
export declare function POST(request: NextRequest): Promise<NextResponse<{
|
|
3
|
+
error: string;
|
|
4
|
+
}> | NextResponse<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
profile_picture_url: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}>>;
|
|
9
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/hazo_auth/upload_profile_picture/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAaxD,wBAAsB,IAAI,CAAC,OAAO,EAAE,WAAW;;;;;;IA2P9C"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// file_description: API route for uploading profile pictures
|
|
2
|
+
// section: imports
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { get_hazo_connect_instance } from "../../../../lib/hazo_connect_instance.server";
|
|
5
|
+
import { create_app_logger } from "../../../../lib/app_logger";
|
|
6
|
+
import { get_profile_picture_config } from "../../../../lib/profile_picture_config.server";
|
|
7
|
+
import { get_file_types_config } from "../../../../lib/file_types_config.server";
|
|
8
|
+
import { update_user_profile_picture } from "../../../../lib/services/profile_picture_service";
|
|
9
|
+
import { createCrudService } from "hazo_connect/server";
|
|
10
|
+
import { map_db_source_to_ui } from "../../../../lib/services/profile_picture_source_mapper";
|
|
11
|
+
import { get_filename, get_line_number } from "../../../../lib/utils/api_route_helpers";
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
import path from "path";
|
|
14
|
+
// section: api_handler
|
|
15
|
+
export async function POST(request) {
|
|
16
|
+
const logger = create_app_logger();
|
|
17
|
+
try {
|
|
18
|
+
// Use centralized auth check
|
|
19
|
+
let user_id;
|
|
20
|
+
try {
|
|
21
|
+
const { require_auth } = await import("../../../../lib/auth/auth_utils.server");
|
|
22
|
+
const user = await require_auth(request);
|
|
23
|
+
user_id = user.user_id;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error && error.message === "Authentication required") {
|
|
27
|
+
logger.warn("profile_picture_upload_authentication_failed", {
|
|
28
|
+
filename: get_filename(),
|
|
29
|
+
line_number: get_line_number(),
|
|
30
|
+
error: "User not authenticated",
|
|
31
|
+
});
|
|
32
|
+
return NextResponse.json({ error: "Authentication required" }, { status: 401 });
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
// Check if upload is enabled
|
|
37
|
+
const config = get_profile_picture_config();
|
|
38
|
+
if (!config.allow_photo_upload) {
|
|
39
|
+
logger.warn("profile_picture_upload_disabled", {
|
|
40
|
+
filename: get_filename(),
|
|
41
|
+
line_number: get_line_number(),
|
|
42
|
+
user_id,
|
|
43
|
+
});
|
|
44
|
+
return NextResponse.json({ error: "Photo upload is not enabled" }, { status: 403 });
|
|
45
|
+
}
|
|
46
|
+
if (!config.upload_photo_path) {
|
|
47
|
+
logger.warn("profile_picture_upload_path_not_configured", {
|
|
48
|
+
filename: get_filename(),
|
|
49
|
+
line_number: get_line_number(),
|
|
50
|
+
user_id,
|
|
51
|
+
});
|
|
52
|
+
return NextResponse.json({ error: "Upload path is not configured" }, { status: 500 });
|
|
53
|
+
}
|
|
54
|
+
// Get FormData
|
|
55
|
+
const formData = await request.formData();
|
|
56
|
+
const file = formData.get("file");
|
|
57
|
+
if (!file) {
|
|
58
|
+
logger.warn("profile_picture_upload_no_file", {
|
|
59
|
+
filename: get_filename(),
|
|
60
|
+
line_number: get_line_number(),
|
|
61
|
+
user_id,
|
|
62
|
+
});
|
|
63
|
+
return NextResponse.json({ error: "No file provided" }, { status: 400 });
|
|
64
|
+
}
|
|
65
|
+
// Validate file type
|
|
66
|
+
const fileTypes = get_file_types_config();
|
|
67
|
+
const fileType = file.type;
|
|
68
|
+
if (!fileTypes.allowed_image_mime_types.includes(fileType)) {
|
|
69
|
+
logger.warn("profile_picture_upload_invalid_type", {
|
|
70
|
+
filename: get_filename(),
|
|
71
|
+
line_number: get_line_number(),
|
|
72
|
+
user_id,
|
|
73
|
+
fileType,
|
|
74
|
+
});
|
|
75
|
+
return NextResponse.json({ error: "Invalid file type. Only JPG and PNG files are allowed." }, { status: 400 });
|
|
76
|
+
}
|
|
77
|
+
// Validate file size (should already be compressed client-side, but check server-side too)
|
|
78
|
+
const fileSize = file.size;
|
|
79
|
+
if (fileSize > config.max_photo_size) {
|
|
80
|
+
logger.warn("profile_picture_upload_too_large", {
|
|
81
|
+
filename: get_filename(),
|
|
82
|
+
line_number: get_line_number(),
|
|
83
|
+
user_id,
|
|
84
|
+
fileSize,
|
|
85
|
+
maxSize: config.max_photo_size,
|
|
86
|
+
});
|
|
87
|
+
return NextResponse.json({ error: `File size exceeds maximum allowed size of ${config.max_photo_size} bytes` }, { status: 400 });
|
|
88
|
+
}
|
|
89
|
+
// Get current user profile picture info before updating
|
|
90
|
+
const hazoConnect = get_hazo_connect_instance();
|
|
91
|
+
const users_service = createCrudService(hazoConnect, "hazo_users");
|
|
92
|
+
const current_users = await users_service.findBy({ id: user_id });
|
|
93
|
+
let oldProfilePictureUrl = null;
|
|
94
|
+
let oldProfileSource = null;
|
|
95
|
+
if (Array.isArray(current_users) && current_users.length > 0) {
|
|
96
|
+
const current_user = current_users[0];
|
|
97
|
+
oldProfilePictureUrl = current_user.profile_picture_url || null;
|
|
98
|
+
oldProfileSource = current_user.profile_source || null;
|
|
99
|
+
}
|
|
100
|
+
// Determine file extension from MIME type
|
|
101
|
+
const mimeToExt = {
|
|
102
|
+
"image/jpeg": "jpg",
|
|
103
|
+
"image/jpg": "jpg",
|
|
104
|
+
"image/png": "png",
|
|
105
|
+
};
|
|
106
|
+
const fileExtension = mimeToExt[fileType] || "jpg";
|
|
107
|
+
const fileName = `${user_id}.${fileExtension}`;
|
|
108
|
+
// Resolve upload path
|
|
109
|
+
const uploadPath = path.isAbsolute(config.upload_photo_path)
|
|
110
|
+
? config.upload_photo_path
|
|
111
|
+
: path.resolve(process.cwd(), config.upload_photo_path);
|
|
112
|
+
// Create upload directory if it doesn't exist
|
|
113
|
+
if (!fs.existsSync(uploadPath)) {
|
|
114
|
+
fs.mkdirSync(uploadPath, { recursive: true });
|
|
115
|
+
}
|
|
116
|
+
// Save file
|
|
117
|
+
const filePath = path.join(uploadPath, fileName);
|
|
118
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
119
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
120
|
+
fs.writeFileSync(filePath, buffer);
|
|
121
|
+
// Generate URL (relative to public or absolute)
|
|
122
|
+
// For Next.js, we'll serve from a public route or use absolute path
|
|
123
|
+
// For now, use a relative path that can be served via API or static file serving
|
|
124
|
+
const profilePictureUrl = `/api/hazo_auth/profile_picture/${fileName}`;
|
|
125
|
+
// Update user record
|
|
126
|
+
const updateResult = await update_user_profile_picture(hazoConnect, user_id, profilePictureUrl, "upload");
|
|
127
|
+
if (!updateResult.success) {
|
|
128
|
+
// Clean up uploaded file
|
|
129
|
+
try {
|
|
130
|
+
fs.unlinkSync(filePath);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
// Ignore cleanup errors
|
|
134
|
+
}
|
|
135
|
+
logger.warn("profile_picture_upload_update_failed", {
|
|
136
|
+
filename: get_filename(),
|
|
137
|
+
line_number: get_line_number(),
|
|
138
|
+
user_id,
|
|
139
|
+
error: updateResult.error,
|
|
140
|
+
});
|
|
141
|
+
return NextResponse.json({ error: updateResult.error || "Failed to update profile picture" }, { status: 500 });
|
|
142
|
+
}
|
|
143
|
+
// Delete old profile picture file if it exists and was an uploaded file
|
|
144
|
+
if (oldProfilePictureUrl && oldProfileSource) {
|
|
145
|
+
const oldSourceUI = map_db_source_to_ui(oldProfileSource);
|
|
146
|
+
// Only delete if the old profile picture was an uploaded file
|
|
147
|
+
if (oldSourceUI === "upload") {
|
|
148
|
+
try {
|
|
149
|
+
// Extract filename from URL (e.g., /api/hazo_auth/profile_picture/user_id.jpg)
|
|
150
|
+
const oldFileName = oldProfilePictureUrl.split("/").pop();
|
|
151
|
+
if (oldFileName) {
|
|
152
|
+
// Check if it's a user-specific file (starts with user_id)
|
|
153
|
+
if (oldFileName.startsWith(user_id)) {
|
|
154
|
+
const oldFilePath = path.join(uploadPath, oldFileName);
|
|
155
|
+
// Only delete if it's a different file (different extension)
|
|
156
|
+
if (oldFilePath !== filePath && fs.existsSync(oldFilePath)) {
|
|
157
|
+
fs.unlinkSync(oldFilePath);
|
|
158
|
+
logger.info("profile_picture_old_file_deleted", {
|
|
159
|
+
filename: get_filename(),
|
|
160
|
+
line_number: get_line_number(),
|
|
161
|
+
user_id,
|
|
162
|
+
oldFileName,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
// Log error but don't fail the request
|
|
170
|
+
logger.warn("profile_picture_old_file_delete_failed", {
|
|
171
|
+
filename: get_filename(),
|
|
172
|
+
line_number: get_line_number(),
|
|
173
|
+
user_id,
|
|
174
|
+
oldProfilePictureUrl,
|
|
175
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
logger.info("profile_picture_upload_successful", {
|
|
181
|
+
filename: get_filename(),
|
|
182
|
+
line_number: get_line_number(),
|
|
183
|
+
user_id,
|
|
184
|
+
fileName,
|
|
185
|
+
fileSize,
|
|
186
|
+
});
|
|
187
|
+
return NextResponse.json({
|
|
188
|
+
success: true,
|
|
189
|
+
profile_picture_url: profilePictureUrl,
|
|
190
|
+
message: "Profile picture uploaded successfully",
|
|
191
|
+
}, { status: 200 });
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
const error_message = error instanceof Error ? error.message : "Unknown error";
|
|
195
|
+
const error_stack = error instanceof Error ? error.stack : undefined;
|
|
196
|
+
logger.error("profile_picture_upload_error", {
|
|
197
|
+
filename: get_filename(),
|
|
198
|
+
line_number: get_line_number(),
|
|
199
|
+
error_message,
|
|
200
|
+
error_stack,
|
|
201
|
+
});
|
|
202
|
+
return NextResponse.json({ error: "Failed to upload profile picture. Please try again." }, { status: 500 });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/hazo_auth/validate_reset_token/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOxD,eAAO,MAAM,OAAO,kBAAkB,CAAC;AAGvC,wBAAsB,GAAG,CAAC,OAAO,EAAE,WAAW;;IAqE7C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// file_description: API route for validating password reset token without resetting password
|
|
2
|
+
// section: imports
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { get_hazo_connect_instance } from "../../../../lib/hazo_connect_instance.server";
|
|
5
|
+
import { validate_password_reset_token } from "../../../../lib/services/password_reset_service";
|
|
6
|
+
import { create_app_logger } from "../../../../lib/app_logger";
|
|
7
|
+
import { get_filename, get_line_number } from "../../../../lib/utils/api_route_helpers";
|
|
8
|
+
// section: route_config
|
|
9
|
+
export const dynamic = 'force-dynamic';
|
|
10
|
+
// section: api_handler
|
|
11
|
+
export async function GET(request) {
|
|
12
|
+
const logger = create_app_logger();
|
|
13
|
+
try {
|
|
14
|
+
const { searchParams } = new URL(request.url);
|
|
15
|
+
const token = searchParams.get("token");
|
|
16
|
+
// Validate input
|
|
17
|
+
if (!token) {
|
|
18
|
+
logger.warn("password_reset_token_validation_failed", {
|
|
19
|
+
filename: get_filename(),
|
|
20
|
+
line_number: get_line_number(),
|
|
21
|
+
error: "Token is required",
|
|
22
|
+
});
|
|
23
|
+
return NextResponse.json({ success: false, error: "Token is required" }, { status: 400 });
|
|
24
|
+
}
|
|
25
|
+
// Get singleton hazo_connect instance (reuses same connection across all routes)
|
|
26
|
+
const hazoConnect = get_hazo_connect_instance();
|
|
27
|
+
// Validate token using the password reset service
|
|
28
|
+
const result = await validate_password_reset_token(hazoConnect, {
|
|
29
|
+
token,
|
|
30
|
+
});
|
|
31
|
+
if (!result.success) {
|
|
32
|
+
logger.warn("password_reset_token_validation_failed", {
|
|
33
|
+
filename: get_filename(),
|
|
34
|
+
line_number: get_line_number(),
|
|
35
|
+
error: result.error,
|
|
36
|
+
});
|
|
37
|
+
return NextResponse.json({
|
|
38
|
+
success: false,
|
|
39
|
+
error: result.error || "Invalid or expired reset token",
|
|
40
|
+
}, { status: 400 });
|
|
41
|
+
}
|
|
42
|
+
return NextResponse.json({
|
|
43
|
+
success: true,
|
|
44
|
+
}, { status: 200 });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
const error_message = error instanceof Error ? error.message : "Unknown error";
|
|
48
|
+
logger.error("password_reset_token_validation_error", {
|
|
49
|
+
filename: get_filename(),
|
|
50
|
+
line_number: get_line_number(),
|
|
51
|
+
error: error_message,
|
|
52
|
+
});
|
|
53
|
+
return NextResponse.json({
|
|
54
|
+
success: false,
|
|
55
|
+
error: "An error occurred while validating the reset token",
|
|
56
|
+
}, { status: 500 });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
export declare const dynamic = "force-dynamic";
|
|
3
|
+
export declare function GET(request: NextRequest): Promise<NextResponse<{
|
|
4
|
+
error: string;
|
|
5
|
+
}> | NextResponse<{
|
|
6
|
+
success: boolean;
|
|
7
|
+
message: string;
|
|
8
|
+
user_id: string | undefined;
|
|
9
|
+
email: string | undefined;
|
|
10
|
+
}>>;
|
|
11
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/hazo_auth/verify_email/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOxD,eAAO,MAAM,OAAO,kBAAkB,CAAC;AAGvC,wBAAsB,GAAG,CAAC,OAAO,EAAE,WAAW;;;;;;;IA0E7C"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// file_description: API route for email verification using hazo_connect
|
|
2
|
+
// section: imports
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { get_hazo_connect_instance } from "../../../../lib/hazo_connect_instance.server";
|
|
5
|
+
import { create_app_logger } from "../../../../lib/app_logger";
|
|
6
|
+
import { verify_email_token } from "../../../../lib/services/email_verification_service";
|
|
7
|
+
import { get_filename, get_line_number } from "../../../../lib/utils/api_route_helpers";
|
|
8
|
+
// section: route_config
|
|
9
|
+
export const dynamic = 'force-dynamic';
|
|
10
|
+
// section: api_handler
|
|
11
|
+
export async function GET(request) {
|
|
12
|
+
const logger = create_app_logger();
|
|
13
|
+
try {
|
|
14
|
+
const { searchParams } = new URL(request.url);
|
|
15
|
+
const token = searchParams.get("token");
|
|
16
|
+
// Validate input
|
|
17
|
+
if (!token) {
|
|
18
|
+
logger.warn("email_verification_validation_failed", {
|
|
19
|
+
filename: get_filename(),
|
|
20
|
+
line_number: get_line_number(),
|
|
21
|
+
has_token: false,
|
|
22
|
+
});
|
|
23
|
+
return NextResponse.json({ error: "Verification token is required" }, { status: 400 });
|
|
24
|
+
}
|
|
25
|
+
// Get singleton hazo_connect instance (reuses same connection across all routes)
|
|
26
|
+
const hazoConnect = get_hazo_connect_instance();
|
|
27
|
+
// Verify email token using the email verification service
|
|
28
|
+
const result = await verify_email_token(hazoConnect, {
|
|
29
|
+
token,
|
|
30
|
+
});
|
|
31
|
+
if (!result.success) {
|
|
32
|
+
logger.warn("email_verification_failed", {
|
|
33
|
+
filename: get_filename(),
|
|
34
|
+
line_number: get_line_number(),
|
|
35
|
+
error: result.error,
|
|
36
|
+
});
|
|
37
|
+
return NextResponse.json({ error: result.error || "Email verification failed" }, { status: 400 });
|
|
38
|
+
}
|
|
39
|
+
logger.info("email_verification_successful", {
|
|
40
|
+
filename: get_filename(),
|
|
41
|
+
line_number: get_line_number(),
|
|
42
|
+
user_id: result.user_id,
|
|
43
|
+
email: result.email,
|
|
44
|
+
});
|
|
45
|
+
return NextResponse.json({
|
|
46
|
+
success: true,
|
|
47
|
+
message: "Email verified successfully",
|
|
48
|
+
user_id: result.user_id,
|
|
49
|
+
email: result.email,
|
|
50
|
+
}, { status: 200 });
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const error_message = error instanceof Error ? error.message : "Unknown error";
|
|
54
|
+
const error_stack = error instanceof Error ? error.stack : undefined;
|
|
55
|
+
logger.error("email_verification_error", {
|
|
56
|
+
filename: get_filename(),
|
|
57
|
+
line_number: get_line_number(),
|
|
58
|
+
error_message,
|
|
59
|
+
error_stack,
|
|
60
|
+
});
|
|
61
|
+
return NextResponse.json({ error: "Email verification failed. Please try again." }, { status: 500 });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/cli/generate.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAwJF,wBAAgB,eAAe,CAAC,OAAO,GAAE,eAAoB,GAAG,IAAI,CA8DnE"}
|