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