Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

feat: remove beta checks (#1276)

__aadamwf037b58a4007
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
index 0600a221..42e157fd 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
@@ -1,10 +1,9 @@
import { auth, type Session } from '@repo/auth/server';
-import { notFound, redirect } from 'next/navigation';
+import { notFound } from 'next/navigation';
import { buildMetaForChallenge, buildMetaForEventPage } from '~/app/metadata';
import { daysAfterDecemberFirst } from '~/utils/aot';
import { getAllFlags } from '~/utils/feature-flags';
import { getRelativeTime } from '~/utils/relativeTime';
-import { isBetaUser } from '~/utils/server/is-beta-user';
import { Comments } from '../_components/comments';
import { Description } from '../_components/description';
import { AOT_CHALLENGES } from './aot-slugs';
@@ -37,13 +36,7 @@ export async function generateMetadata({ params: { slug } }: Props) {
}
export default async function Challenges({ params: { slug } }: Props) {
- // early access you must be authorized
const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
const { enableHolidayEvent } = await getAllFlags();
const isAotChallenge = AOT_CHALLENGES.includes(slug);
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/[solutionId]/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/solutions/[solutionId]/page.tsx
index 2a5796e4..00fe6031 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/[solutionId]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/[solutionId]/page.tsx
@@ -3,8 +3,6 @@ import { SolutionDetails } from '../_components/solution-detail';
import { auth } from '@repo/auth/server';
import { Comments } from '~/app/[locale]/challenge/_components/comments';
import { getSolutionIdRouteData } from './getSolutionIdRouteData';
-import { isBetaUser } from '~/utils/server/is-beta-user';
-import { redirect } from 'next/navigation';
interface Props {
params: {
@@ -16,11 +14,6 @@ interface Props {
export type ChallengeSolution = NonNullable<Awaited<ReturnType<typeof getSolutionIdRouteData>>>;
export default async function SolutionPage({ params: { solutionId, slug } }: Props) {
const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
const solution = await getSolutionIdRouteData(slug, solutionId, session);
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/page.tsx
index cb269627..97a0a8e8 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/page.tsx
@@ -1,8 +1,7 @@
import { auth } from '@repo/auth/server';
import { prisma } from '@repo/db';
-import { notFound, redirect } from 'next/navigation';
+import { notFound } from 'next/navigation';
import { cache } from 'react';
-import { isBetaUser } from '~/utils/server/is-beta-user';
import { withUnstableCache } from '~/utils/withUnstableCache';
import { Submissions } from './_components';
import { createChallengeSubmissionCacheKey } from './cache-keys';
@@ -20,11 +19,6 @@ export const metadata = {
export default async function SubmissionPage({ params: { slug } }: Props) {
const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
const submissions = await withUnstableCache({
fn: getChallengeSubmissions,
diff --git a/apps/web/src/app/[locale]/claim/_actions.ts b/apps/web/src/app/[locale]/claim/_actions.ts
deleted file mode 100644
index 3b87ed0b..00000000
--- a/apps/web/src/app/[locale]/claim/_actions.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-'use server';
-import { auth, type Session } from '@repo/auth/server';
-import { prisma } from '@repo/db';
-import { redirect } from 'next/navigation';
-import { claimFormSchema } from './_schema';
-import { type FormSchema } from './claim-form';
-
-export async function validateToken(claimFormData: FormSchema) {
- claimFormSchema.parse(claimFormData);
-
- const session = await auth();
-
- if (!session) {
- throw new Error('Not authenticated');
- }
-
- await prisma.betaTokens.update({
- where: {
- token: claimFormData.code,
- AND: {
- userId: null,
- },
- },
- data: {
- user: { connect: { id: session?.user?.id } },
- },
- });
-
- redirect('/explore');
-}
-
-export async function isValidToken(session: Session, claimFormData: FormSchema) {
- try {
- claimFormSchema.parse(claimFormData);
-
- await prisma.betaTokens.update({
- where: {
- token: claimFormData.code,
- AND: {
- userId: null,
- },
- },
- data: {
- user: { connect: { id: session?.user?.id } },
- },
- });
- return true;
- } catch (e) {
- return false;
- }
-}
diff --git a/apps/web/src/app/[locale]/claim/_schema.ts b/apps/web/src/app/[locale]/claim/_schema.ts
deleted file mode 100644
index 26621c29..00000000
--- a/apps/web/src/app/[locale]/claim/_schema.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { z } from 'zod';
-
-export const claimFormSchema = z.object({
- code: z
- .string()
- .min(10, {
- message: 'Token must be 10 characters long',
- })
- .max(10),
-});
diff --git a/apps/web/src/app/[locale]/claim/claim-form.tsx b/apps/web/src/app/[locale]/claim/claim-form.tsx
deleted file mode 100644
index c211e52b..00000000
--- a/apps/web/src/app/[locale]/claim/claim-form.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-'use client';
-
-import { zodResolver } from '@hookform/resolvers/zod';
-import { Button } from '@repo/ui/components/button';
-import { Form, FormControl, FormField, FormItem, FormMessage } from '@repo/ui/components/form';
-import { Input } from '@repo/ui/components/input';
-import { toast } from '@repo/ui/components/use-toast';
-import { useForm } from 'react-hook-form';
-import { type z } from 'zod';
-import { validateToken } from './_actions';
-import { claimFormSchema } from './_schema';
-
-export type FormSchema = z.infer<typeof claimFormSchema>;
-export function ClaimForm() {
- const form = useForm<FormSchema>({
- resolver: zodResolver(claimFormSchema),
- defaultValues: {
- code: '',
- },
- });
-
- async function onSubmit(data: FormSchema) {
- try {
- await validateToken(data);
- toast({
- title: 'Token accepted!',
- });
- } catch (e) {
- toast({
- variant: 'destructive',
- title: 'Invalid token',
- });
- }
- }
- return (
- <Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit)} className="mx-auto flex gap-3">
- <FormField
- control={form.control}
- name="code"
- render={({ field }) => (
- <FormItem className="w-64">
- <FormControl>
- <Input
- maxLength={10}
- className="h-10 rounded-xl border border-neutral-400 bg-neutral-200 dark:border-neutral-700 dark:bg-neutral-800"
- placeholder="Enter Early Access token"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <Button className="h-10 rounded-xl" type="submit" disabled={form.formState.isSubmitting}>
- Submit
- </Button>
- </form>
- </Form>
- );
-}
diff --git a/apps/web/src/app/[locale]/claim/page.tsx b/apps/web/src/app/[locale]/claim/page.tsx
deleted file mode 100644
index 1d0ffd01..00000000
--- a/apps/web/src/app/[locale]/claim/page.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import { auth } from '@repo/auth/server';
-import Image from 'next/image';
-import { redirect } from 'next/navigation';
-import { isBetaUser } from '~/utils/server/is-beta-user';
-import { LoginButton } from '../login/_components/LoginButton';
-import { isValidToken } from './_actions';
-import { ClaimForm } from './claim-form';
-
-interface Props {
- searchParams?: { token: string };
-}
-
-export default async function Claim({ searchParams }: Props) {
- const token = searchParams?.token;
- const session = await auth();
-
- if (session && token) {
- if (await isValidToken(session, { code: token })) {
- return redirect('/explore');
- }
- }
-
- const isBeta = await isBetaUser(session);
- if (isBeta) {
- return redirect('/explore');
- }
-
- const redirectUrl = token ? `/claim?token=${token}` : '/claim';
-
- const header = session ? 'In early access?' : 'Login to claim your token';
- const subheader = session ? 'Enter the token that was emailed to you' : '';
- return (
- <div className="container -mt-[56px] flex h-screen flex-col items-center justify-center">
- <div className="mx-auto flex w-full flex-col justify-center space-y-6 text-center sm:w-[550px]">
- <Image
- className="animate-amogup -z-10 mx-auto -mb-48"
- alt="Early Access"
- src="/Red.webp"
- height="198"
- width="150"
- />
- <div className="from-background flex flex-col space-y-3 bg-gradient-to-t from-[42%] to-transparent pt-24 text-center">
- <h1 className="text-4xl font-bold tracking-tight text-neutral-900 dark:text-white">
- {header}
- </h1>
- <p>{subheader}</p>
- {session ? <ClaimForm /> : <LoginButton redirectTo={redirectUrl} />}
- </div>
- </div>
- </div>
- );
-}
diff --git a/apps/web/src/app/[locale]/explore/_components/index.tsx b/apps/web/src/app/[locale]/explore/_components/index.tsx
index 9dacc09d..1ad1f7c5 100644
--- a/apps/web/src/app/[locale]/explore/_components/index.tsx
+++ b/apps/web/src/app/[locale]/explore/_components/index.tsx
@@ -1,8 +1,6 @@
import { auth } from '@repo/auth/server';
-import { redirect } from 'next/navigation';
import { Suspense } from 'react';
import { Footsies } from '~/components/footsies';
-import { isBetaUser } from '~/utils/server/is-beta-user';
import { ExploreSection } from './explore-section';
import { ExploreSectionSkeleton } from './explore-section-skeleton';
import { FemPromo } from '../../aot-2023/_components/fem-promo';
@@ -12,11 +10,6 @@ export const dynamic = 'force-dynamic';
export async function Explore() {
const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
return (
<>
diff --git a/apps/web/src/app/[locale]/tracks/[slug]/page.tsx b/apps/web/src/app/[locale]/tracks/[slug]/page.tsx
index a27304dc..8fe05627 100644
--- a/apps/web/src/app/[locale]/tracks/[slug]/page.tsx
+++ b/apps/web/src/app/[locale]/tracks/[slug]/page.tsx
@@ -1,6 +1,5 @@
import { auth } from '@repo/auth/server';
-import { redirect } from 'next/navigation';
-import { isBetaUser } from '~/utils/server/is-beta-user';
+
import { withUnstableCache } from '~/utils/withUnstableCache';
import { TrackDetail } from '../_components/track-details';
import { getTrackDetails } from '../_components/track.action';
@@ -13,14 +12,8 @@ interface Props {
};
}
-// todo: write a suspense skeleton...
export default async function Page({ params }: Props) {
const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
return <TrackDetail slug={params.slug} />;
}
diff --git a/apps/web/src/app/[locale]/tracks/_components/index.tsx b/apps/web/src/app/[locale]/tracks/_components/index.tsx
index d5eb2f88..992a1094 100644
--- a/apps/web/src/app/[locale]/tracks/_components/index.tsx
+++ b/apps/web/src/app/[locale]/tracks/_components/index.tsx
@@ -1,19 +1,8 @@
-import { auth } from '@repo/auth/server';
-import { redirect } from 'next/navigation';
-import { isBetaUser } from '~/utils/server/is-beta-user';
import { EnrolledTrackSection } from './track-enrolled-section';
import { TrackGrid } from './track-grid';
import { Footsies } from '~/components/footsies';
export async function Tracks() {
- // early acces you must be authorized
- const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
-
return (
<>
<div className="flex flex-col gap-5 pb-8 md:gap-10 md:py-5">
diff --git a/apps/web/src/app/[locale]/wizard/page.tsx b/apps/web/src/app/[locale]/wizard/page.tsx
index 737fcf4e..3badd694 100644
--- a/apps/web/src/app/[locale]/wizard/page.tsx
+++ b/apps/web/src/app/[locale]/wizard/page.tsx
@@ -1,8 +1,5 @@
-import { auth } from '@repo/auth/server';
import type { Metadata } from 'next';
-import { redirect } from 'next/navigation';
import { buildMetaForDefault } from '~/app/metadata';
-import { isBetaUser } from '~/utils/server/is-beta-user';
import { Wizard } from './_components';
export async function generateMetadata(): Promise<Metadata> {
@@ -13,12 +10,5 @@ export async function generateMetadata(): Promise<Metadata> {
}
export default async function Page() {
- const session = await auth();
- const isBeta = await isBetaUser(session);
-
- if (!isBeta) {
- return redirect('/claim');
- }
-
return <Wizard />;
}
diff --git a/apps/web/src/utils/server/is-beta-user.ts b/apps/web/src/utils/server/is-beta-user.ts
deleted file mode 100644
index b65d9ecd..00000000
--- a/apps/web/src/utils/server/is-beta-user.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import type { Session } from '@repo/auth/server';
-import { prisma } from '@repo/db';
-import { getAllFlags } from '../feature-flags';
-
-export async function isBetaUser(session: Session | null) {
- const flags = await getAllFlags();
-
- const isBetaUser = await prisma.betaTokens.findFirst({
- where: {
- userId: session?.user?.id ?? '',
- },
- });
-
- if ((!session || !isBetaUser) && flags.enableEarlyAccess) {
- return false;
- }
-
- return true;
-}