62
import { computed, ref } from "vue"
63
import Api from "@/api"
64
import Icon from "@/components/common/Icon.vue"
65
+import { useAuthStore } from "@/stores/auth"
66
import { getApiErrorMessage } from "@/utils"
67
68
const emit = defineEmits<{
74
const loading = defineModel<boolean>("loading", { default: false })
75
76
const message = useMessage()
77
+const authStore = useAuthStore()
78
const currentPassword = ref("")
79
const newPassword = ref("")
80
const confirmPassword = ref("")
106
return
107
}
108
107
- // Validate password length
108
- if (newPassword.value.length < 8) {
109
- message.error("Password must be at least 8 characters long")
109
+ // Mirror the backend complexity requirements so the user gets a clear message
110
+ // instead of an opaque 422 from the API.
111
+ if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]{8,72}$/.test(newPassword.value)) {
112
+ message.error(
113
+ "Password must be 8-72 characters and include an uppercase letter, a lowercase letter, a number, and a special character (@$!%*?&#)"
114
+ )
115
+ return
116
+ }
117
+
118
+ const username = authStore.userName
119
+ if (!username) {
120
+ message.error("Authentication required. Please log in again.")
121
return
122
}
123
124
loading.value = true
125
126
try {
116
- // Get token and username from localStorage
117
- const token = localStorage.getItem("customer-portal-auth-token")
118
- const userStr = localStorage.getItem("customer-portal-user")
119
-
120
- if (!token || !userStr) {
121
- message.error("Authentication required. Please log in again.")
122
- return
123
- }
124
-
125
- const user = JSON.parse(userStr)
126
- const username = user.username
127
-
128
- // Call the reset-password/me endpoint
129
- const response = await Api.auth.resetPassword(username, newPassword.value)
127
+ // Token is injected by the HTTP client from the auth store.
128
+ const response = await Api.auth.resetPassword(username, newPassword.value, currentPassword.value)
129
130
if (response.data.success) {
131
message.success("Password changed successfully!")