Email SMTP Fix

This commit is contained in:
Koncept Kit
2025-12-07 16:59:21 +07:00
parent 7b8ee6442a
commit 79cebd205c
15 changed files with 978 additions and 78 deletions

View File

@@ -71,8 +71,73 @@ export const AuthProvider = ({ children }) => {
}
};
const forgotPassword = async (email) => {
const response = await axios.post(`${API_URL}/api/auth/forgot-password`, { email });
return response.data;
};
const resetPassword = async (token, newPassword) => {
const response = await axios.post(`${API_URL}/api/auth/reset-password`, {
token,
new_password: newPassword
});
return response.data;
};
const changePassword = async (currentPassword, newPassword) => {
const currentToken = localStorage.getItem('token');
if (!currentToken) {
throw new Error('Not authenticated');
}
const response = await axios.put(
`${API_URL}/api/users/change-password`,
{
current_password: currentPassword,
new_password: newPassword
},
{
headers: { Authorization: `Bearer ${currentToken}` }
}
);
// Refresh user data to clear force_password_change flag if it was set
await refreshUser();
return response.data;
};
const resendVerificationEmail = async () => {
const currentToken = localStorage.getItem('token');
if (!currentToken) {
throw new Error('Not authenticated');
}
const response = await axios.post(
`${API_URL}/api/auth/resend-verification-email`,
{},
{
headers: { Authorization: `Bearer ${currentToken}` }
}
);
return response.data;
};
return (
<AuthContext.Provider value={{ user, token, login, logout, register, refreshUser, loading }}>
<AuthContext.Provider value={{
user,
token,
login,
logout,
register,
refreshUser,
forgotPassword,
resetPassword,
changePassword,
resendVerificationEmail,
loading
}}>
{children}
</AuthContext.Provider>
);