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

ENH: Leveage T3 ENV Type safety #1290

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ GITHUB_SECRET=
NEXT_PUBLIC_DISCORD_WEBHOOK_URL =
JOB_BOARD_AUTH_SECRET=

FETCHER_URL=
VIZOLV_SECRET=
DISCORD_REDIRECT_URI=

COHORT3_DISCORD_ACCESS_KEY =
COHORT3_DISCORD_ACCESS_SECRET =
Expand Down
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tooltip": "^1.0.7",
"@t3-oss/env-nextjs": "^0.11.1",
"@tabler/icons-react": "^3.14.0",
"@types/bcrypt": "^5.0.2",
"@types/jsonwebtoken": "^9.0.5",
Expand Down
5 changes: 3 additions & 2 deletions src/actions/comment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createSafeAction } from '@/lib/create-safe-action';
import { CommentType, Prisma } from '@prisma/client';
import { revalidatePath } from 'next/cache';
import { ROLES } from '../types';
import { env } from '@/env';

export const getComments = async (
q: Prisma.CommentFindManyArgs,
Expand Down Expand Up @@ -273,7 +274,7 @@ const updateCommentHandler = async (
content: content ?? existingComment.content,
approved: existingComment.approved,
};
if (adminPassword === process.env.ADMIN_SECRET) {
if (adminPassword === env.ADMIN_SECRET) {
updObj.approved = approved ?? existingComment.approved;
}
const updatedComment = await prisma.comment.update({
Expand All @@ -295,7 +296,7 @@ const approveIntroCommentHandler = async (
const { content_comment_ids, approved, adminPassword, currentPath } = data;

if (adminPassword) {
if (adminPassword !== process.env.ADMIN_SECRET) {
if (adminPassword !== env.ADMIN_SECRET) {
return { error: 'Unauthorized' };
}
} else if (!session || !session.user || session.user.role !== ROLES.ADMIN) {
Expand Down
3 changes: 2 additions & 1 deletion src/actions/event-actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server';

import prisma from '@/db';
import { env } from '@/env';
import { authOptions } from '@/lib/auth';
import { Event } from '@prisma/client';
import { getServerSession } from 'next-auth';
Expand All @@ -9,7 +10,7 @@ import { revalidatePath } from 'next/cache';

async function isAdmin() {
const session = await getServerSession(authOptions);
const adminEmails = process.env.ADMINS?.split(',') || [];
const adminEmails = env.ADMINS?.split(',') || [];
return session?.user?.email && adminEmails.includes(session.user.email);
}

Expand Down
3 changes: 2 additions & 1 deletion src/actions/refresh-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import db from '@/db';
import { cache } from '@/db/Cache';
import { getAllCourses } from '@/db/course';
import { env } from '@/env';
import { authOptions } from '@/lib/auth';
import { APPX_COURSE_IDS } from '@/utiles/appx';
import { checkUserEmailForPurchase } from '@/utiles/appx-check-mail';
Expand All @@ -28,7 +29,7 @@ export async function refreshDbInternal(userId?: string, email?: string) {
};
}

if (process.env.LOCAL_CMS_PROVIDER) {
if (env.LOCAL_CMS_PROVIDER) {
return { error: false, message: 'Refetched Courses' };
}

Expand Down
3 changes: 2 additions & 1 deletion src/actions/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use server';
import db from '@/db';
import { env } from '@/env';

export const logoutUser = async (email: string, adminPassword: string) => {
if (adminPassword !== process.env.ADMIN_SECRET) {
if (adminPassword !== env.ADMIN_SECRET) {
return { error: 'Unauthorized' };
}

Expand Down
124 changes: 79 additions & 45 deletions src/app/admin/add-course/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use client';

import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import {
Form,
FormControl,
Expand All @@ -29,7 +24,7 @@ import {
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
} from '@/components/ui/accordion';
import { Cuboid, PackagePlus } from 'lucide-react';
import { FaDiscord } from 'react-icons/fa';

Expand Down Expand Up @@ -86,24 +81,32 @@ export default function Courses() {

return (
<div className="wrapper my-16 flex flex-col gap-4">

<section className='flex gap-2 border-2 p-4 bg-primary/5 rounded-lg my-4 items-center'>
<section className="my-4 flex items-center gap-2 rounded-lg border-2 bg-primary/5 p-4">
<Cuboid size={18} />
<h2 className='text-md font-bold'>View Content</h2>
<h2 className="text-md font-bold">View Content</h2>
</section>

<Accordion defaultValue='add-new-course' className='border-2 p-4 rounded-2xl' type="single" collapsible>
<Accordion
defaultValue="add-new-course"
className="rounded-2xl border-2 p-4"
type="single"
collapsible
>
<AccordionItem value="add-new-course">
<AccordionTrigger className='p-6 text-2xl font-bold'>
<div className='flex gap-4 flex-col' >
<PackagePlus size={40} />New course
<AccordionTrigger className="p-6 text-2xl font-bold">
<div className="flex flex-col gap-4">
<PackagePlus size={40} />
New course
</div>
</AccordionTrigger>
<AccordionContent>
<div className='w-full grid grid-cols-1 lg:grid-cols-7'>
<div className='text-sm font-semibold text-gray-400 col-span-1 lg:col-span-2 p-6'>Create new course for 100xdevs community and let user explore new courses</div>
<div className='col-span-1 lg:col-span-5 p-4'>
<Card className='bg-background border-2'>
<div className="grid w-full grid-cols-1 lg:grid-cols-7">
<div className="col-span-1 p-6 text-sm font-semibold text-gray-400 lg:col-span-2">
Create new course for 100xdevs community and let user explore
new courses
</div>
<div className="col-span-1 p-4 lg:col-span-5">
<Card className="border-2 bg-background">
<CardHeader>
{/* <CardTitle>Create a new course</CardTitle> */}
<CardTitle>Fill in the course details below</CardTitle>
Expand All @@ -121,7 +124,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Title</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Course name" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Course name"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -134,7 +141,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Image url</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the url of Image" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the url of Image"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -144,11 +155,12 @@ export default function Courses() {
control={form.control}
name="description"
render={({ field }: { field: any }) => (
<FormItem className='col-span-1 lg:col-span-2'>
<FormItem className="col-span-1 lg:col-span-2">
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea
className='h-12 px-3' placeholder="Enter the Description of course"
className="h-12 px-3"
placeholder="Enter the Description of course"
{...field}
/>
</FormControl>
Expand All @@ -163,7 +175,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Slug</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Course slug" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Course slug"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -176,7 +192,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Id</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Course ID" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Course ID"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -189,7 +209,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Admin Secret</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Admin Secret" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Admin Secret"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -203,7 +227,8 @@ export default function Courses() {
<FormLabel>app x course id</FormLabel>
<FormControl>
<Input
className='h-12 px-3' placeholder="Enter the appx course ID"
className="h-12 px-3"
placeholder="Enter the appx course ID"
{...field}
/>
</FormControl>
Expand Down Expand Up @@ -231,7 +256,9 @@ export default function Courses() {
{isLoading ? (
<Button>Loading...</Button>
) : (
<Button className='w-[20%]' type="submit">Create</Button>
<Button className="w-[20%]" type="submit">
Create
</Button>
)}
</div>
</form>
Expand All @@ -243,24 +270,28 @@ export default function Courses() {
</AccordionContent>
</AccordionItem>

<AccordionItem className='border-none' value="discord-config">
<AccordionTrigger className='p-6 text-2xl font-bold'>
<div className='flex gap-4 flex-col' >
<FaDiscord className='text-5xl' /> Discord Config
<AccordionItem className="border-none" value="discord-config">
<AccordionTrigger className="p-6 text-2xl font-bold">
<div className="flex flex-col gap-4">
<FaDiscord className="text-5xl" /> Discord Config
</div>
</AccordionTrigger>
<AccordionContent>
<div className='w-full grid grid-cols-1 lg:grid-cols-7'>
<div className='text-sm font-semibold text-gray-400col-span-1 lg:col-span-2 p-6'>Mangae discord configuration for the users</div>
<div className='col-span-1 lg:col-span-5 p-4'>
<Card className='bg-background'>
<div className="grid w-full grid-cols-1 lg:grid-cols-7">
<div className="text-gray-400col-span-1 p-6 text-sm font-semibold lg:col-span-2">
Mangae discord configuration for the users
</div>
<div className="col-span-1 p-4 lg:col-span-5">
<Card className="bg-background">
<CardHeader>
<CardTitle>Discord</CardTitle>
</CardHeader>
<CardContent className="flex flex-col gap-5 lg:flex-row">
<Card className="mx-auto border-2 bg-background w-full max-w-3xl overflow-y-auto">
<Card className="mx-auto w-full max-w-3xl overflow-y-auto border-2 bg-background">
<CardHeader>
<CardTitle>Allow user another account in cohort 3</CardTitle>
<CardTitle>
Allow user another account in cohort 3
</CardTitle>
</CardHeader>
<CardContent className="grid gap-4 p-4 pt-0">
<Input
Expand All @@ -280,10 +311,13 @@ export default function Courses() {
<Button
onClick={async () => {
try {
const res = await axios.post('/api/admin/discordReset', {
email,
adminPassword,
});
const res = await axios.post(
'/api/admin/discordReset',
{
email,
adminPassword,
},
);
toast(JSON.stringify(res.data.data));
} catch (error) {
//@ts-ignore
Expand All @@ -295,9 +329,11 @@ export default function Courses() {
</Button>
</CardContent>
</Card>
<Card className="mx-auto border-2 bg-background w-full max-w-3xl overflow-y-auto">
<Card className="mx-auto w-full max-w-3xl overflow-y-auto border-2 bg-background">
<CardHeader>
<CardTitle>Get users discord username in cohort 3</CardTitle>
<CardTitle>
Get users discord username in cohort 3
</CardTitle>
</CardHeader>
<CardContent className="grid gap-4 p-4 pt-0">
<Input
Expand Down Expand Up @@ -340,9 +376,7 @@ export default function Courses() {
</div>
</AccordionContent>
</AccordionItem>

</Accordion>

</div>
);
}
Loading
Loading