Skip to content

Commit

Permalink
refactor: refactor envs (#100)
Browse files Browse the repository at this point in the history
* refactor: improve envs

* refactor: update homepage text and improve dropdown file

* ci: add envs to playwright github action

* ci: refactor envs

* ci: add all envs
  • Loading branch information
Skolaczk authored May 12, 2024
1 parent 67fdd1e commit 4a5fd08
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Duplicate this to .env
DATABASE_URL='your database url' ## required for prisma - create free PostgreSQL database: https://dashboard.render.com/new/database

NEXT_PUBLIC_SITE_URL='your site url' ## required for next-sitemap, not required for development
APP_URL='your app url' ## required for next-sitemap and stripe

NEXT_PUBLIC_GITHUB_ID='your github client ID' ## required for next-auth
NEXT_PUBLIC_GITHUB_SECRET='your github secret ID' ## required for next-auth
GOOGLE_SITE_VERIFICATION_ID='your google verification id' ## not required

GITHUB_ID='your github client ID' ## required for next-auth
GITHUB_SECRET='your github secret ID' ## required for next-auth

NEXTAUTH_SECRET='your next-auth secret' ## required for next-auth - generate one here: https://generate-secret.vercel.app/32
NEXTAUTH_URL='http://localhost:3000' ## Only required for localhost

NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY='your stripe publishable key' ## required for stripe
STRIPE_SECRET_KEY='your stripe secret key' ## required for stripe
STRIPE_WEBHOOK_SECRET_KEY='your webhook secret key' ## required for stripe
STRIPE_SUBSCRIPTION_PRICE_ID='your subscription price id' ## required for stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY='your stripe publishable key' ## required for stripe
10 changes: 10 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
APP_URL: ${{ secrets.APP_URL }}
GITHUB_ID: ${{ secrets.AUTH_GITHUB_ID }}
GITHUB_SECRET: ${{ secrets.AUTH_GITHUB_SECRET }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_SUBSCRIPTION_PRICE_ID: ${{ secrets.STRIPE_SUBSCRIPTION_PRICE_ID}}
STRIPE_WEBHOOK_SECRET_KEY: ${{ secrets.STRIPE_WEBHOOK_SECRET_KEY }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion next-sitemap.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
siteUrl: process.env.NEXT_PUBLIC_SITE_URL || '',
siteUrl: process.env.APP_URL,
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [{ userAgent: '*', allow: '/' }],
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/auth/[...nextauth]/auth-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
GitHubProvider({
clientId: env.NEXT_PUBLIC_GITHUB_ID || '',
clientSecret: env.NEXT_PUBLIC_GITHUB_SECRET || '',
clientId: env.GITHUB_ID,
clientSecret: env.GITHUB_SECRET,
}),
],
callbacks: {
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/stripe/checkout-session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const GET = async () => {
quantity: 1,
},
],
success_url: `${env.NEXT_PUBLIC_SITE_URL}?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: env.NEXT_PUBLIC_SITE_URL,
success_url: `${env.APP_URL}?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: env.APP_URL,
});

return NextResponse.json({ session: checkoutSession }, { status: 200 });
Expand Down
4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const Home = () => {
</h1>
<p className="text-muted-foreground max-w-2xl">
A Next.js starter template, packed with features like TypeScript,
Tailwind CSS, Next-auth, Eslint, testing tools and more. Jumpstart your
project with efficiency and style.
Tailwind CSS, Next-auth, Eslint, Stripe, testing tools and more.
Jumpstart your project with efficiency and style.
</p>
<div className="mt-1">
<HeroForm />
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DropdownMenuSubContent = React.forwardRef<
<DropdownMenuPrimitive.SubContent
ref={ref}
className={cn(
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-lg',
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-32 overflow-hidden rounded-md border p-1 shadow-lg',
className
)}
{...props}
Expand All @@ -65,7 +65,7 @@ const DropdownMenuContent = React.forwardRef<
ref={ref}
sideOffset={sideOffset}
className={cn(
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-md',
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-32 overflow-hidden rounded-md border p-1 shadow-md',
className
)}
{...props}
Expand Down
27 changes: 16 additions & 11 deletions src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { z } from 'zod';

export const env = createEnv({
server: {
NEXT_PUBLIC_SITE_URL: z.string().url().optional(),
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION_ID: z.string().min(1).optional(),
NEXT_PUBLIC_GITHUB_ID: z.string().min(1).optional(),
NEXT_PUBLIC_GITHUB_SECRET: z.string().min(1).optional(),
DATABASE_URL: z.string().min(1),
APP_URL: z.string().url().min(1),
GOOGLE_SITE_VERIFICATION_ID: z.string().optional(),
GITHUB_ID: z.string().min(1),
GITHUB_SECRET: z.string().min(1),
NEXTAUTH_URL: z.string().url().optional(),
NEXTAUTH_SECRET: z.string().min(1),
STRIPE_SECRET_KEY: z.string().min(1),
STRIPE_WEBHOOK_SECRET_KEY: z.string().min(1),
STRIPE_SUBSCRIPTION_PRICE_ID: z.string().min(1),
Expand All @@ -15,15 +18,17 @@ export const env = createEnv({
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: z.string().min(1),
},
runtimeEnv: {
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION_ID:
process.env.NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION_ID,
NEXT_PUBLIC_GITHUB_ID: process.env.NEXT_PUBLIC_GITHUB_ID,
NEXT_PUBLIC_GITHUB_SECRET: process.env.NEXT_PUBLIC_GITHUB_SECRET,
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
DATABASE_URL: process.env.DATABASE_URL,
APP_URL: process.env.APP_URL,
GOOGLE_SITE_VERIFICATION_ID: process.env.GOOGLE_SITE_VERIFICATION_ID,
GITHUB_ID: process.env.GITHUB_ID,
GITHUB_SECRET: process.env.GITHUB_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
STRIPE_WEBHOOK_SECRET_KEY: process.env.STRIPE_WEBHOOK_SECRET_KEY,
STRIPE_SUBSCRIPTION_PRICE_ID: process.env.STRIPE_SUBSCRIPTION_PRICE_ID,
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY:
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
},
});
4 changes: 2 additions & 2 deletions src/lib/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const siteConfig = {
'Next-auth',
'Prisma',
],
url: env.NEXT_PUBLIC_SITE_URL || 'https://example.com',
googleSiteVerificationId: env.NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION_ID || '',
url: env.APP_URL,
googleSiteVerificationId: env.GOOGLE_SITE_VERIFICATION_ID || '',
};

0 comments on commit 4a5fd08

Please sign in to comment.