import { Button, useBeforeInstallPrompt, usePushSubscription } from "tempest-react-sdk"; import { useAuth } from "@/stores/auth"; /** * Protected page (see the `guard` in src/routes.tsx). Lazy-loaded, so it is * code-split into its own chunk. Default export because `lazy` expects one. * * Adds two PWA controls: * - Install button (`useBeforeInstallPrompt`) โ€” appears only when the browser * offers an install prompt and the app is not yet installed. * - Push toggle (`usePushSubscription`) โ€” subscribes/unsubscribes to web push. * The service worker must be active, so this works in a production build * (`npm run build && npm run preview`), not in `npm run dev`. */ export default function Dashboard() { const user = useAuth.use.user(); const install = useBeforeInstallPrompt(); const push = usePushSubscription({ vapidPublicKey: import.meta.env.VITE_VAPID_PUBLIC_KEY ?? "", onSubscribe: async (subscription) => { // Send the subscription to your backend so it can deliver pushes. // await api.post("/webpush/subscribe", { body: subscription }); console.log("push subscription", subscription); }, onUnsubscribe: async () => { // await api.delete("/webpush/my"); console.log("push unsubscribed"); }, }); return (

Dashboard

Signed in as {user?.name} ({user?.email}).

This route is only reachable while authenticated.

PWA

{install.installed ? (

โœ… App installed.

) : install.installable ? ( ) : (

Install prompt not available in this browser/context.

)}

Notifications

{!push.supported ? (

Web push is not supported here (needs HTTPS + an active service worker).

) : ( <>

Permission: {push.permission} ยท Subscribed:{" "} {String(push.subscribed)}

{push.error &&

{push.error.message}

} )}
); }