feat(#29): Add example product tool requiring purchase to access

This commit is contained in:
Josh Creek
2024-09-22 12:06:39 +01:00
parent a4764c547e
commit fce4c0e0a5
11 changed files with 101 additions and 3 deletions
@@ -0,0 +1,19 @@
/** @type {import('./$types').PageLoad} */
import { redirect } from '@sveltejs/kit';
import { hasProductAccess } from '$lib/utils/supabase/admin';
import { VITE_PRODUCT_ID_EXAMPLEPRODUCT } from '$env/static/private'; // Import the example product ID from env
export const load = async ({ params, locals: { safeGetSession } }) => {
const { session } = await safeGetSession();
if (!session) {
throw redirect(303, '/login'); // Redirect unauthenticated users to login
}
// Check if the user has access to the 'EXAMPLE PRODUCT' product
const accessGranted = await hasProductAccess(session.user.id, VITE_PRODUCT_ID_EXAMPLEPRODUCT);
if (!accessGranted) {
throw redirect(303, '/unauthorised');
}
return params;
};
@@ -0,0 +1,2 @@
<h1>Example Product</h1>
<p>This is an example of a tool you could be selling.</p>