mirror of
https://github.com/fergalmoran/supanextail.git
synced 2025-12-22 09:17:54 +00:00
Continue typescript integration
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
// Helper method to wait for a middleware to execute before continuing
|
||||
// And to throw an error when an error happens in a middleware
|
||||
export default function initMiddleware(middleware) {
|
||||
return (req, res) =>
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
export default function initMiddleware(middleware: any) {
|
||||
return (req: NextApiRequest, res: NextApiResponse) =>
|
||||
new Promise((resolve, reject) => {
|
||||
middleware(req, res, (result) => {
|
||||
middleware(req, res, (result: any) => {
|
||||
if (result instanceof Error) {
|
||||
return reject(result);
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* This is a singleton to ensure we only instantiate Stripe once.
|
||||
*/
|
||||
import { loadStripe } from '@stripe/stripe-js';
|
||||
import { Stripe, loadStripe } from '@stripe/stripe-js';
|
||||
|
||||
let stripePromise = null;
|
||||
const getStripe = () => {
|
||||
let stripePromise: Promise<Stripe | null>;
|
||||
const getStripe = (): Promise<Stripe | null> => {
|
||||
if (!stripePromise) {
|
||||
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY);
|
||||
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY || '');
|
||||
}
|
||||
return stripePromise;
|
||||
};
|
||||
@@ -3,11 +3,11 @@ import { createClient } from '@supabase/supabase-js';
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
|
||||
export const supabase = createClient(supabaseUrl, supabaseAnonKey);
|
||||
export const supabase = createClient(supabaseUrl || '', supabaseAnonKey || '');
|
||||
|
||||
// Check if a user has a paid plan
|
||||
export const getSub = async () => {
|
||||
const { data: subscriptions, error } = await supabase
|
||||
const { data: subscriptions } = await supabase
|
||||
.from('subscriptions')
|
||||
.select('paid_user, plan')
|
||||
.single();
|
||||
Reference in New Issue
Block a user