Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(IGRNOE) Stage #23

Merged
merged 8 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import prisma from "@/lib/client";
import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";
import { sign } from "jsonwebtoken";
import config from "@/config";

const handler = NextAuth({
providers: [
GithubProvider({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
clientId: config.GITHUB_CLIENT_ID as string,
clientSecret: config.GITHUB_CLIENT_SECRET as string,
}),
],
callbacks: {
Expand All @@ -24,7 +25,7 @@ const handler = NextAuth({
},
async jwt({ token, account, user }) {
if (user) {
token.jwtToken = sign(user, process.env.JWT_SECRET as string, {
token.jwtToken = sign(user, config.JWT_SECRET as string, {
algorithm: "HS256",
expiresIn: "100d",
});
Expand All @@ -36,7 +37,7 @@ const handler = NextAuth({
},
},
debug: true,
secret: process.env.NEXTAUTH_SECRET,
secret: config.NEXTAUTH_SECRET,
});

export { handler as GET, handler as POST };
5 changes: 3 additions & 2 deletions app/api/stripe/create-portal-or-checkout-url/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isValidToken } from "@/utils/auth";

import stripe from "@/lib/stripe";
import { createCheckoutSession, hasActiveSubscription } from "@/utils/stripe";
import config from "@/config";
// import { NEXT_PUBLIC_SITE_URL } from "@/lib/constants";

const schema = z.object({
Expand Down Expand Up @@ -42,14 +43,14 @@ export async function POST(req: NextRequest) {
if (await hasActiveSubscription(customerId)) {
session = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: process.env.NEXT_PUBLIC_SITE_URL,
return_url: config.NEXT_PUBLIC_SITE_URL,
});
if (!session.url) throw new Error("No billing portal URL found");
} else {
session = await createCheckoutSession({
customerId,
email: email,
priceId: process.env.STRIPE_STANDARD_PLAN_PRICE_ID || "",
priceId: config.STRIPE_STANDARD_PLAN_PRICE_ID || "",
metadata: {
userId: userId,
userName: userName,
Expand Down
3 changes: 2 additions & 1 deletion app/api/stripe/create-portal-url/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z, ZodError } from "zod";
import { isValidToken } from "@/utils/auth";

import stripe from "@/lib/stripe";
import config from "@/config";

const schema = z.object({
userId: z.number(),
Expand All @@ -22,7 +23,7 @@ export async function POST(req: NextRequest) {

const session = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: process.env.NEXT_PUBLIC_SITE_URL as string,
return_url: config.NEXT_PUBLIC_SITE_URL as string,
});

if (!session.url) throw new Error("No checkout session URL found");
Expand Down
3 changes: 2 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UseCases from "@/components/HomePage/UseCases";
// Analytics
import { usePathname } from "next/navigation";
import { usePostHog } from "posthog-js/react";
import config from "@/config";
export default function Home() {
const buttonStyles = `bg-pink text-white rounded-lg transition-colors
duration-200 text-md sm:text-lg xl:text-xl py-5 px-8 shadow-lg hover:shadow-lg
Expand Down Expand Up @@ -47,7 +48,7 @@ export default function Home() {
 a PR from an issue
</h1>
<a
href={process.env.NEXT_PUBLIC_GITHUB_APP_URL}
href={config.NEXT_PUBLIC_GITHUB_APP_URL}
target="_blank"
onClick={() => {
posthog.capture("$click", {
Expand Down
724 changes: 724 additions & 0 deletions app/privacy-policy/page.mdx

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/redirect-to-install/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Footer from "@/components/Footer";
// Analytics
import { usePathname } from "next/navigation";
import { usePostHog } from "posthog-js/react";
import config from "@/config";

export default function Home() {
const router = useRouter();
Expand All @@ -33,7 +34,7 @@ export default function Home() {
}, 1000);

const timeout = setTimeout(() => {
router.push(process.env.NEXT_PUBLIC_GITHUB_APP_URL as string);
router.push(config.NEXT_PUBLIC_GITHUB_APP_URL as string);
}, 5000);

return () => {
Expand Down
4 changes: 2 additions & 2 deletions components/Context/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isTokenExpired } from "@/utils/auth";
import { signOut, useSession } from "next-auth/react";
import useSWR from "swr";
import { useRouter } from "next/navigation";
import { REDIRECT_GITHUB_APP_URL } from "@/lib/constants";
import config from "@/config";

const AccountContext = createContext<{
userInfos: any; // All users, installations, owners associated with this github account
Expand Down Expand Up @@ -129,7 +129,7 @@ export function AccountContextWrapper({
// If user has no accounts, redirect to github app
useEffect(() => {
if (userInfos && userInfos.length === 0) {
router.push(REDIRECT_GITHUB_APP_URL);
router.push(config.REDIRECT_GITHUB_APP_URL);
}
}, [userInfos, router]);

Expand Down
22 changes: 19 additions & 3 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
faLinkedin,
faYoutube,
} from "@fortawesome/free-brands-svg-icons";
import config from "@/config";

export default function Footer() {
// Analytics
Expand All @@ -26,10 +27,10 @@ export default function Footer() {
<div className="flex w-[95vw] sm:w-[80vw] 2xl:w-[1280px] flex-col justify-center ">
<div className="flex flex-col gap-10 sm:gap-0 sm:flex-row items-center py-10 mt-auto w-full text-black text-lg font-helvetica justify-center ">
<div className="flex flex-wrap gap-20 xl:gap-36 mx-auto w-auto ">
<ol className="flex gap-2">
<ol className="flex gap-5">
<li>
<Link
href={process.env.NEXT_PUBLIC_GITHUB_APP_URL as string}
href={config.NEXT_PUBLIC_GITHUB_APP_URL as string}
passHref
target="_blank"
onClick={() => {
Expand Down Expand Up @@ -66,6 +67,21 @@ export default function Footer() {
Pricing
</a>
</li>
<li>
<Link
href={config.PRIVACY_POLICY_URL}
target="_blank"
onClick={() => {
posthog.capture("$click", {
$event_type: "privacy_policy",
$current_url: window.location.href,
});
}}
className="whitespace-nowrap transition duration-[325ms] hover:text-blue"
>
Privacy Policy
</Link>
</li>
{/* If there is an active subscription, show "Manage Payment" */}
{selectedIndex != null &&
userInfosSubscribed &&
Expand Down Expand Up @@ -104,7 +120,7 @@ export default function Footer() {
</span>
<div className="flex items-center gap-5">
<Link
href={process.env.NEXT_PUBLIC_GITHUB_APP_URL as string}
href={config.NEXT_PUBLIC_GITHUB_APP_URL as string}
passHref
target="_blank"
onClick={() => {
Expand Down
8 changes: 4 additions & 4 deletions components/HomePage/Pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useAccountContext } from "@/components/Context/Account";
import { signIn } from "next-auth/react";

import { Spinner } from "@chakra-ui/react";
import { REDIRECT_GITHUB_APP_URL } from "@/lib/constants";
import config from "@/config";

const pricingButtonStyles = `my-8 rounded-lg transition-colors duration-200
text-md sm:text-lg xl:text-xl py-3 w-[250px] sm:w-[315px] lg:w-[210px] shadow-lg hover:shadow-lg
Expand Down Expand Up @@ -70,7 +70,7 @@ export default function Pricing() {
router.push(res);
} else {
// If not, redirect to installation page
router.push(REDIRECT_GITHUB_APP_URL);
router.push(config.REDIRECT_GITHUB_APP_URL);
}
}, [jwtToken, router, selectedIndex, userId, userInfos]);

Expand All @@ -87,7 +87,7 @@ export default function Pricing() {
createPortalOrCheckoutURL();
} else {
// Signed in but no intallation
router.push(REDIRECT_GITHUB_APP_URL);
router.push(config.REDIRECT_GITHUB_APP_URL);
}
} else {
// Not signed in, prompt sign in
Expand Down Expand Up @@ -126,7 +126,7 @@ export default function Pricing() {
<h3 className="text-3xl">$0</h3>
<span className="mt-2 text-xl">Free</span>
<Link
href={process.env.NEXT_PUBLIC_GITHUB_APP_URL as string}
href={config.NEXT_PUBLIC_GITHUB_APP_URL as string}
passHref
target="_blank"
onClick={() => {
Expand Down
3 changes: 2 additions & 1 deletion components/Navbar/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { signIn, signOut } from "next-auth/react";
import { useSession } from "next-auth/react";
import { useDisclosure } from "@chakra-ui/react";
import SwitchAccount from "../HomePage/SwitchAccount";
import config from "@/config";

interface MobileDrawerProps {
setIsNavOpen: (prev: boolean) => void;
Expand Down Expand Up @@ -121,7 +122,7 @@ export default function MobileDrawer({
<>
<li>
<Link
href={process.env.NEXT_PUBLIC_GITHUB_APP_URL as string}
href={config.NEXT_PUBLIC_GITHUB_APP_URL as string}
passHref
target="_blank"
onClick={() => {
Expand Down
7 changes: 5 additions & 2 deletions components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import Image from "next/image";
import Link from "next/link";
import { useEffect, useState } from "react";
import { usePathname } from "next/navigation";

// Components
import HamburgerMenu from "./hamburgerMenu";
import MobileDrawer from "./MobileMenu";

// Analytics
import { usePathname } from "next/navigation";
import { usePostHog } from "posthog-js/react";

// Third Party
Expand All @@ -17,6 +17,7 @@ import { useSession } from "next-auth/react";

import { motion } from "framer-motion";
import ProfileIcon from "./ProfileIcon";
import config from "@/config";

const buttonStyles = `bg-pink text-white rounded-lg transition-colors
duration-200 py-2 px-3 shadow-lg hover:shadow-lg
Expand All @@ -40,6 +41,8 @@ export default function Navbar() {
}
}, [pathname, posthog]);

if (pathname === config.PRIVACY_POLICY_URL) return null;

return (
<div className="flex flex-col w-full justify-center items-center font-helvetica font-normal bg-white text-black sm:text-md xl:text-lg">
<div className="flex flex-col w-[95vw] sm:w-[80vw] 2xl:w-[1280px]">
Expand Down Expand Up @@ -94,7 +97,7 @@ export default function Navbar() {
<>
<li>
<Link
href={process.env.NEXT_PUBLIC_GITHUB_APP_URL as string}
href={config.NEXT_PUBLIC_GITHUB_APP_URL as string}
passHref
target="_blank"
onClick={() => {
Expand Down
5 changes: 3 additions & 2 deletions components/PostHog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use client";
import config from "@/config";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";

Expand All @@ -8,8 +9,8 @@ import { PostHogProvider } from "posthog-js/react";
// } from "@/lib/constants";

if (typeof window !== "undefined") {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY as string, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST as string,
posthog.init(config.NEXT_PUBLIC_POSTHOG_KEY as string, {
api_host: config.NEXT_PUBLIC_POSTHOG_HOST as string,
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
});
}
Expand Down
42 changes: 42 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import dotenv from "dotenv";
dotenv.config();

// TODO not working because it works on both client and server side, resulting in client side error.
function checkVar(variable: string) {
const thisVariable = process.env[variable];
console.log("THIS VAR: ", thisVariable, variable);
if (!thisVariable) {
throw new Error(`Variable ${thisVariable} is not defined`);
}
return thisVariable;
}

const config = {
// Contants
REDIRECT_GITHUB_APP_URL: "/redirect-to-install",
PRIVACY_POLICY_URL: "/privacy-policy",

// Authentication
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID || "",
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET || "",
JWT_SECRET: process.env.JWT_SECRET || "",
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET || "",

// Stripe

STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY || "",
STRIPE_FREE_TIER_PRICE_ID: process.env.STRIPE_FREE_TIER_PRICE_ID || "",
STRIPE_STANDARD_PLAN_PRICE_ID:
process.env.STRIPE_STANDARD_PLAN_PRICE_ID || "",

// PostHog
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY || "",
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST || "",

// Environment Specifcs
NODE_ENV: process.env.NODE_ENV || "",
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL || "",
NEXT_PUBLIC_GITHUB_APP_URL: process.env.NEXT_PUBLIC_GITHUB_APP_URL || "",
};

export default config;
45 changes: 0 additions & 45 deletions lib/constants.ts

This file was deleted.

3 changes: 2 additions & 1 deletion lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "@/config";
import { PrismaClient } from "@prisma/client";

const globalForPrisma = global as unknown as { prisma: PrismaClient };
Expand All @@ -10,4 +11,4 @@ export const prisma =
log: ["error"],
});

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
if (config.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
3 changes: 2 additions & 1 deletion lib/stripe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Stripe from "stripe";
// Get Stripe Secret Key from environment variables
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
import config from "@/config";
const STRIPE_SECRET_KEY = config.STRIPE_SECRET_KEY;
if (!STRIPE_SECRET_KEY) throw new Error("STRIPE_SECRET_KEY is not set");

/**
Expand Down
Loading
Loading