diff --git a/src/components/NavBar.jsx b/src/components/NavBar.jsx
index 0ec51fa..54a6aa3 100644
--- a/src/components/NavBar.jsx
+++ b/src/components/NavBar.jsx
@@ -1,30 +1,153 @@
+'use client';
+
+import { Suspense } from 'react';
+
+import Image from 'next/image';
+import { usePathname } from 'next/navigation';
+
+import { Fragment } from 'react'
+import { Disclosure, Menu, Transition } from '@headlessui/react'
+import { Bars3Icon, UserCircleIcon, XMarkIcon } from '@heroicons/react/24/outline'
+
+import trsLogo from '@/images/trs-logo.svg';
+
import Link from 'next/link'
-export default function NavBar({ showPodcast }) {
+const navigation = [
+ { name: 'Contact', href: '/contact-us' },
+ { name: 'Book', href: '/book' },
+]
+
+function classNames(...classes) {
+ return classes.filter(Boolean).join(' ')
+}
+
+export default function NavBar({ userMenu, reactorsLink }) {
+ const pathname = usePathname();
return (
-
+
+ {({ open }) => (
+ <>
+
+
+
+ {/* Mobile menu button*/}
+
+ Open main menu
+ {open ? (
+
+ ) : (
+
+ )}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Reactors
+
+ )}>
+ {reactorsLink}
+
+ {navigation.map((item) => (
+
+ {item.name}
+
+ ))}
+
+
+
+
+
+ {/* Profile dropdown */}
+
+
+
+
+
+
+
+
+
+ Reactors
+
+ )}>
+ {reactorsLink}
+
+
+ {navigation.map((item) => (
+
+
+ {item.name}
+
+
+ ))}
+
+
+ >
+ )}
+
)
}
diff --git a/src/components/ReactorsLink.jsx b/src/components/ReactorsLink.jsx
new file mode 100644
index 0000000..afac82b
--- /dev/null
+++ b/src/components/ReactorsLink.jsx
@@ -0,0 +1,45 @@
+'use server';
+
+import Link from 'next/link';
+
+import UserMenuClient from '@/components/UserMenuClient';
+
+import { cookies } from 'next/headers';
+
+import db from '@/db';
+
+async function getSession() {
+ const cookieStore = cookies();
+ const sessionId = cookieStore.get('session');
+ if (!sessionId) {
+ return false;
+ }
+ const { user_id: userId } = await db.get('select user_id from sessions where session_id=?;', sessionId.value);
+ if (!userId) {
+ return false;
+ }
+ return userId;
+};
+
+export default async function ReactorsLink() {
+ const userId = await getSession();
+ if (userId) {
+ return (
+
+ Reactors
+
+ )
+ } else {
+ return (
+
+ Reactors
+
+ );
+ }
+};
diff --git a/src/components/UserMenu.jsx b/src/components/UserMenu.jsx
new file mode 100644
index 0000000..af5f20a
--- /dev/null
+++ b/src/components/UserMenu.jsx
@@ -0,0 +1,70 @@
+'use server';
+
+import Link from 'next/link';
+
+import UserMenuClient from '@/components/UserMenuClient';
+
+import { cookies } from 'next/headers';
+
+import db from '@/db';
+
+const signedInNavigation = [
+ { name: 'Account', href: '/reactors/account' },
+ { name: 'Sign Out', href: '/' },
+]
+
+async function getSession() {
+ const cookieStore = cookies();
+ const sessionId = cookieStore.get('session');
+ if (!sessionId) {
+ return false;
+ }
+ const { user_id: userId } = await db.get('select user_id from sessions where session_id=?;', sessionId.value);
+ if (!userId) {
+ return false;
+ }
+ return userId;
+};
+
+export default async function UserMenu() {
+ const userId = await getSession();
+ return (
+
+ {userId ? (
+ <>
+
+ Account
+
+
+ >
+ ) : (
+ <>
+
+ Sign In
+
+
+ Create Account
+
+ >
+ )}
+
+ );
+};
diff --git a/src/components/UserMenuClient.jsx b/src/components/UserMenuClient.jsx
new file mode 100644
index 0000000..326e2a4
--- /dev/null
+++ b/src/components/UserMenuClient.jsx
@@ -0,0 +1,72 @@
+'use client';
+
+import { Fragment } from 'react'
+import { Disclosure, Menu, Transition } from '@headlessui/react'
+import { Bars3Icon, UserCircleIcon, XMarkIcon } from '@heroicons/react/24/outline'
+
+function classNames(...classes) {
+ return classes.filter(Boolean).join(' ')
+}
+
+export default function UserMenu({ children }) {
+ return (
+ <>
+
+
+ Open user menu
+
+
+
+
+
+ {children.map((link, i) => (
+
+ {link}
+
+ ))}
+
+
+ >
+ );
+};
+
+/*
+ * {({ active }) => (
+ *
+ * Your Profile
+ *
+ * )}
+ *
+ *
+ * {({ active }) => (
+ *
+ * Settings
+ *
+ * )}
+ *
+ *
+ * {({ active }) => (
+ *
+ * Sign out
+ *
+ * )}
+ * */
diff --git a/src/db.js b/src/db.js
index a45c45d..a481119 100644
--- a/src/db.js
+++ b/src/db.js
@@ -78,6 +78,11 @@ foreign key (user_id) references users (id)
key: 9,
name: 'add audio size column',
sql: [`alter table episodes add column audio_size integer;`]
+ },
+ {
+ key: 10,
+ name: 'add subscription type column',
+ sql: [`alter table subscriptions add column type text;`]
}
];
diff --git a/src/images/reactors3.jpeg b/src/images/reactors3.jpeg
new file mode 100644
index 0000000..842143b
Binary files /dev/null and b/src/images/reactors3.jpeg differ
diff --git a/src/images/reactors4.jpeg b/src/images/reactors4.jpeg
new file mode 100644
index 0000000..1ab4f83
Binary files /dev/null and b/src/images/reactors4.jpeg differ
diff --git a/src/images/trs-logo.svg b/src/images/trs-logo.svg
new file mode 100644
index 0000000..d50e5b2
--- /dev/null
+++ b/src/images/trs-logo.svg
@@ -0,0 +1,274 @@
+
+
diff --git a/src/pages/api/create-account.js b/src/pages/api/create-account.js
index e2112af..b8156df 100644
--- a/src/pages/api/create-account.js
+++ b/src/pages/api/create-account.js
@@ -41,8 +41,8 @@ const createUser = async (email, salt, hashRes) => {
};
// Create a new subscription for the user
-const createSubscription = async (userId) => {
- await db.run('insert into subscriptions (uuid, user_id) values (?, ?);', randomUUID(), userId);
+const createSubscription = async (userId, type) => {
+ await db.run('insert into subscriptions (uuid, user_id, type) values (?, ?, ?);', randomUUID(), userId, type);
};
async function handler(req, res) {
@@ -61,6 +61,7 @@ async function handler(req, res) {
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 sessionType = session && session?.metadata?.type;
// Validate session and email
if (!session || !emailFromSession || email !== emailFromSession) {
@@ -84,22 +85,22 @@ async function handler(req, res) {
const salt = genSalt();
const hashRes = await hash(salt, password);
const userId = await createUser(email, salt, hashRes);
- await createSubscription(userId);
+ await createSubscription(userId, sessionType);
console.log('User created successfully');
- res.redirect('/reactors');
+ res.status(303).redirect('/reactors/account');
} else {
// Handle missing or invalid form data
if (!email || !csi) {
console.error('Missing email or csi');
- res.redirect('/reactors/create-account?unexpected_error=true');
+ res.status(303).redirect('/reactors/create-account?unexpected_error=true');
return;
}
if (!password) {
- res.redirect(makeMsg(csi, email, 'Please enter a password'));
+ res.status(303).redirect(makeMsg(csi, email, 'Please enter a password'));
return;
}
if (password !== passwordagain) {
- res.redirect(makeMsg(csi, email, 'Passwords did not match. Please try again.'));
+ res.status(303).redirect(makeMsg(csi, email, 'Passwords did not match. Please try again.'));
return;
}
}
diff --git a/src/pages/api/sign-in.js b/src/pages/api/sign-in.js
index 8ea44a6..95c7490 100644
--- a/src/pages/api/sign-in.js
+++ b/src/pages/api/sign-in.js
@@ -46,16 +46,16 @@ async function handler(req, res) {
const expiresDate = new Date(today.getTime() + (1000 * maxAge));
await db.run('insert into sessions (user_id, session_id, expires) values (?, ?, ?);', userId, sessionId, expiresDate.toISOString());
setCookie('session', sessionId, { req, res, maxAge: rememberMe ? maxAge : undefined, httpOnly: true, sameSite: true, secure: process.env.NODE_ENV === 'production' });
- res.redirect('/reactors/account')
+ res.status(303).redirect('/reactors/account')
} else {
- res.redirect(makeMsg(email, 'Invalid password or account does not exist.'));
+ res.status(303).redirect(makeMsg(email, 'Invalid password or account does not exist.'));
}
} else {
if (!email) {
- res.redirect(makeMsg(email, 'Please enter an email address.'));
+ res.status(303).redirect(makeMsg(email, 'Please enter an email address.'));
}
if (!password) {
- res.redirect(makeMsg(email, 'Please enter a password.'));
+ res.status(303).redirect(makeMsg(email, 'Please enter a password.'));
}
}
} else {
diff --git a/src/pages/api/sign-out.js b/src/pages/api/sign-out.js
index 614b407..2ac6e1f 100644
--- a/src/pages/api/sign-out.js
+++ b/src/pages/api/sign-out.js
@@ -3,7 +3,7 @@ import { deleteCookie } from 'cookies-next';
export default async function handler(req, res) {
if (req.method === 'POST') {
deleteCookie('session', { req, res, httpOnly: true, sameSite: true, secure: process.env.NODE_ENV === 'production' });
- res.redirect('/reactors');
+ res.status(303).redirect('/');
} else {
// Handle any other HTTP method
}