@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
26 lines • 1.04 kB
JavaScript
import { useCallback } from "react";
import axios from "../../config/axios";
import useProject from "../projects/useProject";
import { useReplykeDispatch } from "../../store/hooks";
import { updateUserOptimistic } from "../../store/slices/userSlice";
function useVerifyEmail() {
const { projectId } = useProject();
const dispatch = useReplykeDispatch();
const verifyEmail = useCallback(async ({ token }) => {
if (!projectId) {
throw new Error("No projectId available.");
}
if (!token?.trim()) {
throw new Error("Verification token is required.");
}
const response = await axios.post(`/${projectId}/auth/verify-email`, {
token: token.trim(),
});
// Update local state immediately so the UI reflects the verified status
dispatch(updateUserOptimistic({ isVerified: true }));
return response.data;
}, [projectId, dispatch]);
return verifyEmail;
}
export default useVerifyEmail;
//# sourceMappingURL=useVerifyEmail.js.map