@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
31 lines • 1.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const axios_1 = __importDefault(require("../../config/axios"));
const useProject_1 = __importDefault(require("../projects/useProject"));
const hooks_1 = require("../../store/hooks");
const userSlice_1 = require("../../store/slices/userSlice");
function useVerifyEmail() {
const { projectId } = (0, useProject_1.default)();
const dispatch = (0, hooks_1.useReplykeDispatch)();
const verifyEmail = (0, react_1.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_1.default.post(`/${projectId}/auth/verify-email`, {
token: token.trim(),
});
// Update local state immediately so the UI reflects the verified status
dispatch((0, userSlice_1.updateUserOptimistic)({ isVerified: true }));
return response.data;
}, [projectId, dispatch]);
return verifyEmail;
}
exports.default = useVerifyEmail;
//# sourceMappingURL=useVerifyEmail.js.map