Typescript first integration + fix all eslint errors (97 warnings)

This commit is contained in:
Michael
2021-08-10 22:03:23 +02:00
parent 8d69135404
commit 2cccdba402
55 changed files with 10477 additions and 2308 deletions

View File

@@ -6,53 +6,47 @@ import { supabase } from 'utils/supabaseClient';
const AuthContext = createContext();
export const AuthProvider = ({ children }) => {
const [user, setUser] = useState();
const [loading, setLoading] = useState(true);
const [user, setUser] = useState();
const [loading, setLoading] = useState(true);
useEffect(() => {
// Check active sessions and sets the user
const session = supabase.auth.session();
useEffect(() => {
// Check active sessions and sets the user
const session = supabase.auth.session();
setUser(session?.user ?? null);
setLoading(false);
setUser(session?.user ?? null);
setLoading(false);
// Listen for changes on auth state (logged in, signed out, etc.)
const { data: listener } = supabase.auth.onAuthStateChange(
async (event, session) => {
if ((event === 'SIGNED_OUT') | (event === 'SIGNED_IN')) {
fetch('/api/auth', {
method: 'POST',
headers: new Headers({ 'Content-Type': 'application/json' }),
credentials: 'same-origin',
body: JSON.stringify({ event, session }),
}).then((res) => res.json());
}
if (event === 'USER_UPDATED') {
}
setUser(session?.user ?? null);
setLoading(false);
}
);
// Listen for changes on auth state (logged in, signed out, etc.)
const { data: listener } = supabase.auth.onAuthStateChange(async (event, session) => {
if ((event === 'SIGNED_OUT') | (event === 'SIGNED_IN')) {
fetch('/api/auth', {
method: 'POST',
headers: new Headers({ 'Content-Type': 'application/json' }),
credentials: 'same-origin',
body: JSON.stringify({ event, session }),
}).then((res) => res.json());
}
if (event === 'USER_UPDATED') {
}
setUser(session?.user ?? null);
setLoading(false);
});
return () => {
listener?.unsubscribe();
};
}, []);
return () => {
listener?.unsubscribe();
};
}, []);
// Will be passed down to Signup, Login and Dashboard components
const value = {
signUp: (data) => supabase.auth.signUp(data),
signIn: (data) => supabase.auth.signIn(data),
signOut: () => supabase.auth.signOut(),
resetPassword: (data) => supabase.auth.api.resetPasswordForEmail(data),
user,
};
// Will be passed down to Signup, Login and Dashboard components
const value = {
signUp: (data) => supabase.auth.signUp(data),
signIn: (data) => supabase.auth.signIn(data),
signOut: () => supabase.auth.signOut(),
resetPassword: (data) => supabase.auth.api.resetPasswordForEmail(data),
user,
};
return (
<AuthContext.Provider value={value}>
{!loading && children}
</AuthContext.Provider>
);
return <AuthContext.Provider value={value}>{!loading && children}</AuthContext.Provider>;
};
// export the useAuth hook

View File

@@ -1,13 +1,13 @@
// 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) =>
new Promise((resolve, reject) => {
middleware(req, res, (result) => {
if (result instanceof Error) {
return reject(result);
}
return resolve(result);
});
});
return (req, res) =>
new Promise((resolve, reject) => {
middleware(req, res, (result) => {
if (result instanceof Error) {
return reject(result);
}
return resolve(result);
});
});
}

View File

@@ -1,45 +1,45 @@
// You can store your price IDs from Stripe here
const Prices = {
personal: {
monthly: {
id: 'price_1J5q2yDMjD0UnVmMXzEWYDnl',
desc: 'Personal plan (monthly)',
},
annually: {
id: 'price_1J5q45DMjD0UnVmMQxXHKGAv',
desc: 'Personal plan (annually)',
},
},
team: {
monthly: {
id: 'price_1J5q3GDMjD0UnVmMlHc5Eedq',
desc: 'Team plan (monthly)',
},
annually: {
id: 'price_1J5q8zDMjD0UnVmMqsngM91X',
desc: 'Team plan (annually)',
},
},
pro: {
monthly: {
id: 'price_1J6KRuDMjD0UnVmMIItaOdT3',
desc: 'Pro plan (monthly)',
},
annually: {
id: 'price_1J5q9VDMjD0UnVmMIQtVDSZ9',
desc: 'Pro plan (annually)',
},
},
personal: {
monthly: {
id: 'price_1J5q2yDMjD0UnVmMXzEWYDnl',
desc: 'Personal plan (monthly)',
},
annually: {
id: 'price_1J5q45DMjD0UnVmMQxXHKGAv',
desc: 'Personal plan (annually)',
},
},
team: {
monthly: {
id: 'price_1J5q3GDMjD0UnVmMlHc5Eedq',
desc: 'Team plan (monthly)',
},
annually: {
id: 'price_1J5q8zDMjD0UnVmMqsngM91X',
desc: 'Team plan (annually)',
},
},
pro: {
monthly: {
id: 'price_1J6KRuDMjD0UnVmMIItaOdT3',
desc: 'Pro plan (monthly)',
},
annually: {
id: 'price_1J5q9VDMjD0UnVmMIQtVDSZ9',
desc: 'Pro plan (annually)',
},
},
};
const PriceIds = {
price_1J5q2yDMjD0UnVmMXzEWYDnl: 'Personal plan (monthly)',
price_1J5q45DMjD0UnVmMQxXHKGAv: 'Personal plan (annually)',
price_1J5q3GDMjD0UnVmMlHc5Eedq: 'Team plan (monthly)',
price_1J5q8zDMjD0UnVmMqsngM91X: 'Team plan (annually)',
price_1J6KRuDMjD0UnVmMIItaOdT3: 'Pro plan (monthly)',
price_1J5q9VDMjD0UnVmMIQtVDSZ9: 'Pro plan (annually)',
price_1J5q2yDMjD0UnVmMXzEWYDnl: 'Personal plan (monthly)',
price_1J5q45DMjD0UnVmMQxXHKGAv: 'Personal plan (annually)',
price_1J5q3GDMjD0UnVmMlHc5Eedq: 'Team plan (monthly)',
price_1J5q8zDMjD0UnVmMqsngM91X: 'Team plan (annually)',
price_1J6KRuDMjD0UnVmMIItaOdT3: 'Pro plan (monthly)',
price_1J5q9VDMjD0UnVmMIQtVDSZ9: 'Pro plan (annually)',
};
export { Prices, PriceIds };

View File

@@ -5,10 +5,10 @@ import { loadStripe } from '@stripe/stripe-js';
let stripePromise = null;
const getStripe = () => {
if (!stripePromise) {
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY);
}
return stripePromise;
if (!stripePromise) {
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY);
}
return stripePromise;
};
export default getStripe;

View File

@@ -7,11 +7,11 @@ export const supabase = createClient(supabaseUrl, supabaseAnonKey);
// Check if a user has a paid plan
export const getSub = async () => {
const { data: subscriptions, error } = await supabase
.from('subscriptions')
.select('paid_user, plan')
.single();
if (subscriptions) {
return subscriptions;
}
const { data: subscriptions, error } = await supabase
.from('subscriptions')
.select('paid_user, plan')
.single();
if (subscriptions) {
return subscriptions;
}
};