mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 02:53:50 +00:00
feat(#29): Add example product tool requiring purchase to access
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user