feat: update dependencies and refactor layout and homepage components
- Added new dependencies: @daveyplate/better-auth-ui, next-themes, and sonner. - Refactored layout component to use Providers and Toaster for better state management and notifications. - Updated homepage to utilize authClient for session management and improved user experience with navigation links for sign-in and sign-up.
This commit is contained in:
33
components/init-user.tsx
Normal file
33
components/init-user.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { useMutation, useQuery } from "convex/react";
|
||||
import { api } from "@/convex/_generated/api";
|
||||
import { useEffect } from "react";
|
||||
|
||||
/**
|
||||
* Initialisiert die Credit-Balance für neue User.
|
||||
* Wird einmal im Layout eingebunden und sorgt dafür,
|
||||
* dass jeder eingeloggte User eine Balance + Free-Subscription hat.
|
||||
*/
|
||||
export function InitUser() {
|
||||
const { data: session } = authClient.useSession();
|
||||
const balance = useQuery(
|
||||
api.credits.getBalance,
|
||||
session?.user ? {} : "skip"
|
||||
);
|
||||
const initBalance = useMutation(api.credits.initBalance);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
session?.user &&
|
||||
balance &&
|
||||
balance.balance === 0 &&
|
||||
balance.monthlyAllocation === 0
|
||||
) {
|
||||
initBalance();
|
||||
}
|
||||
}, [session?.user, balance, initBalance]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user