Continue typescript integration

This commit is contained in:
Michael
2021-08-24 11:57:13 +02:00
parent 5a24246d09
commit a7c614bcc9
22 changed files with 278 additions and 85 deletions

View File

@@ -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);
}

View File

@@ -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;
};

View File

@@ -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();