update pay function
This commit is contained in:
54
boilerplate-chakra-pro-main/app/supabase-server.ts
Normal file
54
boilerplate-chakra-pro-main/app/supabase-server.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Database } from '@/types_db';
|
||||
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs';
|
||||
import { cookies } from 'next/headers';
|
||||
import { cache } from 'react';
|
||||
|
||||
export const createServerSupabaseClient = cache(() =>
|
||||
createServerComponentClient<Database>({ cookies })
|
||||
);
|
||||
|
||||
export async function getUserDetails() {
|
||||
const supabase = createServerSupabaseClient();
|
||||
try {
|
||||
const { data: userDetails } = await supabase
|
||||
.from('users')
|
||||
.select('*')
|
||||
.single();
|
||||
return userDetails;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSubscription() {
|
||||
const supabase = createServerSupabaseClient();
|
||||
try {
|
||||
const { data: subscription } = await supabase
|
||||
.from('subscriptions')
|
||||
.select('*, prices(*, products(*))')
|
||||
.in('status', ['trialing', 'active'])
|
||||
.maybeSingle()
|
||||
.throwOnError();
|
||||
return subscription;
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const getActiveProductsWithPrices = async () => {
|
||||
const supabase = createServerSupabaseClient();
|
||||
const { data, error } = await supabase
|
||||
.from('products')
|
||||
.select('*, prices(*)')
|
||||
.eq('active', true)
|
||||
.eq('prices.active', true)
|
||||
.order('metadata->index')
|
||||
.order('unit_amount', { foreignTable: 'prices' });
|
||||
|
||||
if (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
return data ?? [];
|
||||
};
|
||||
Reference in New Issue
Block a user