Adding support for patreon account creation.
This commit is contained in:
@@ -3,7 +3,6 @@ export const dynamic = 'force-dynamic';
|
||||
import Link from 'next/link'
|
||||
import Stripe from 'stripe';
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
|
||||
import { dbRun } from '@/db';
|
||||
|
||||
import { XCircleIcon } from '@heroicons/react/20/solid'
|
||||
|
||||
@@ -15,12 +14,9 @@ export default async function Page({ searchParams }) {
|
||||
const unexpectedError = searchParams['unexpected_error'];
|
||||
const msg = searchParams['msg'];
|
||||
const csi = searchParams['csi'];
|
||||
const patreonMagicKey = searchParams['patreon_magic_key'];
|
||||
const session = csi && await stripe.checkout.sessions.retrieve(csi);
|
||||
const email = (csi && session && session.customer_details.email) || searchParams['email'];
|
||||
const message = searchParams['message'];
|
||||
const submitted = email || message;
|
||||
const valid = submitted && email && message;
|
||||
let emailSentSuccessfully = false;
|
||||
if (unexpectedError) {
|
||||
return (
|
||||
<>
|
||||
@@ -59,6 +55,11 @@ export default async function Page({ searchParams }) {
|
||||
value={csi}
|
||||
type="hidden"
|
||||
/>
|
||||
<input
|
||||
name="patreon_magic_key"
|
||||
value={patreonMagicKey}
|
||||
type="hidden"
|
||||
/>
|
||||
<div className="space-y-8">
|
||||
<div className="pt-8">
|
||||
<div className="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
|
||||
|
||||
@@ -47,18 +47,19 @@ const createSubscription = async (userId) => {
|
||||
|
||||
async function handler(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
const { email, password, passwordagain, csi } = req.body;
|
||||
const { email, password, passwordagain, csi, patreon_magic_key } = req.body;
|
||||
|
||||
// Validate email, password, and csi
|
||||
if (email && password && password === passwordagain && csi) {
|
||||
if (email && password && password === passwordagain && (csi || patreon_magic_key)) {
|
||||
// Check for minimum password length
|
||||
if (password.length < 12) {
|
||||
res.redirect(makeMsg(csi, email, 'Please enter a password that is at least 12 characters long.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve Stripe session and email
|
||||
const session = csi && await stripe.checkout.sessions.retrieve(csi);
|
||||
// Retrieve Stripe session and email or get verify patreon magic key
|
||||
const session = (csi && await stripe.checkout.sessions.retrieve(csi)) ||
|
||||
(patreon_magic_key === process.env.PATREON_MAGIC_KEY ? { customer_details: { email } } : false);
|
||||
const emailFromSession = session && session.customer_details.email;
|
||||
|
||||
// Validate session and email
|
||||
|
||||
Reference in New Issue
Block a user