B2B-88: add starter kit structure and elements

This commit is contained in:
devmc-ee
2025-06-08 16:18:30 +03:00
parent 657a36a298
commit e7b25600cb
1280 changed files with 77893 additions and 5688 deletions

View File

@@ -0,0 +1,14 @@
import { createBrowserClient } from '@supabase/ssr';
import { Database } from '../database.types';
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
/**
* @name getSupabaseBrowserClient
* @description Get a Supabase client for use in the Browser
*/
export function getSupabaseBrowserClient<GenericSchema = Database>() {
const keys = getSupabaseClientKeys();
return createBrowserClient<GenericSchema>(keys.url, keys.anonKey);
}

View File

@@ -0,0 +1,38 @@
import 'server-only';
import { type NextRequest, NextResponse } from 'next/server';
import { createServerClient } from '@supabase/ssr';
import { Database } from '../database.types';
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
/**
* Creates a middleware client for Supabase.
*
* @param {NextRequest} request - The Next.js request object.
* @param {NextResponse} response - The Next.js response object.
*/
export function createMiddlewareClient<GenericSchema = Database>(
request: NextRequest,
response: NextResponse,
) {
const keys = getSupabaseClientKeys();
return createServerClient<GenericSchema>(keys.url, keys.anonKey, {
cookies: {
getAll() {
return request.cookies.getAll();
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value }) =>
request.cookies.set(name, value),
);
cookiesToSet.forEach(({ name, value, options }) =>
response.cookies.set(name, value, options),
);
},
},
});
}

View File

@@ -0,0 +1,28 @@
import 'server-only';
import { createClient } from '@supabase/supabase-js';
import { Database } from '../database.types';
import {
getServiceRoleKey,
warnServiceRoleKeyUsage,
} from '../get-service-role-key';
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
/**
* @name getSupabaseServerAdminClient
* @description Get a Supabase client for use in the Server with admin access to the database.
*/
export function getSupabaseServerAdminClient<GenericSchema = Database>() {
warnServiceRoleKeyUsage();
const url = getSupabaseClientKeys().url;
return createClient<GenericSchema>(url, getServiceRoleKey(), {
auth: {
persistSession: false,
detectSessionInUrl: false,
autoRefreshToken: false,
},
});
}

View File

@@ -0,0 +1,39 @@
import 'server-only';
import { cookies } from 'next/headers';
import { createServerClient } from '@supabase/ssr';
import { Database } from '../database.types';
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
/**
* @name getSupabaseServerClient
* @description Creates a Supabase client for use in the Server.
*/
export function getSupabaseServerClient<GenericSchema = Database>() {
const keys = getSupabaseClientKeys();
return createServerClient<GenericSchema>(keys.url, keys.anonKey, {
cookies: {
async getAll() {
const cookieStore = await cookies();
return cookieStore.getAll();
},
async setAll(cookiesToSet) {
const cookieStore = await cookies();
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options),
);
} catch {
// The `setAll` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
});
}