feat: initial commit — storefront, convex backend, and shared packages
Completes the first milestone of The Pet Loft ecommerce platform: - apps/storefront: full customer-facing Next.js app with HeroUI (cart, checkout, orders, wishlist, product detail, shop, search, auth) - convex/: serverless backend with schema, queries, mutations, actions, HTTP routes, Stripe/Shippo integrations, and co-located tests - packages/types, packages/utils, packages/convex: shared workspace packages Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
31
apps/storefront/src/hooks/useStoreUserEffect.ts
Normal file
31
apps/storefront/src/hooks/useStoreUserEffect.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { useUser } from "@clerk/nextjs";
|
||||
import { useConvexAuth, useMutation } from "convex/react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { api } from "../../../../convex/_generated/api";
|
||||
import { Id } from "../../../../convex/_generated/dataModel";
|
||||
|
||||
export function useStoreUserEffect() {
|
||||
const { isLoading, isAuthenticated } = useConvexAuth();
|
||||
const { user } = useUser();
|
||||
const [userId, setUserId] = useState<Id<"users"> | null>(null);
|
||||
const storeUser = useMutation(api.users.store);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) return;
|
||||
let cancelled = false;
|
||||
storeUser().then((id) => {
|
||||
if (!cancelled) setUserId(id);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
setUserId(null);
|
||||
};
|
||||
}, [isAuthenticated, storeUser, user?.id]);
|
||||
|
||||
return {
|
||||
isLoading: isLoading || (isAuthenticated && userId === null),
|
||||
isAuthenticated: isAuthenticated && userId !== null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user