Skip to content
Draft
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
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
AUTH_SECRET="openssl rand -hex 32"
BETTER_AUTH_SECRET="openssl rand -hex 32"
BETTER_AUTH_URL=http://localhost:3000

DATABASE_URL="postgresql://username:password@localhost:5432/db_name"

NEXT_PUBLIC_SENTRY_DSN="https://<number>@<number>.ingest.de.sentry.io/<number>"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- 🔗 [Eslint](https://eslint.org/)
- 🔗 [ShadCN/ui](https://ui.shadcn.com/)
- 🔗 [Sentry](https://bit.ly/sentry-docs-dg)
- 🔗 [Kinde Auth](https://kinde.com/dgray-nextjsstack/)
- 🔗 [Better Auth](https://www.better-auth.com)
- 🔗 [Neon Postgres](https://fyi.neon.tech/davegray)
- 🔗 [Prisma ORM](https://www.prisma.io/)
- 🔗 [react-hook-form](https://react-hook-form.com/)
Expand Down
5 changes: 5 additions & 0 deletions app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PropsWithChildren } from 'react';

export default function AuthLayout({ children }: Readonly<PropsWithChildren>) {
return <main className='flex h-screen flex-col items-center justify-center'>{children}</main>;
}
File renamed without changes.
20 changes: 20 additions & 0 deletions app/(auth)/sign-in/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { SignInForm } from '@/features/auth';

export default function SignInPage() {
return (
<div className='flex min-h-svh w-full items-center justify-center p-6 md:p-10'>
<div className='w-full max-w-md'>
<Card>
<CardHeader>
<CardTitle className='text-2xl'>Sign In</CardTitle>
<CardDescription>Enter your email below to login to your account</CardDescription>
</CardHeader>
<CardContent>
<SignInForm />
</CardContent>
</Card>
</div>
</div>
);
}
20 changes: 20 additions & 0 deletions app/(auth)/sign-up/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { SignUpForm } from '@/features/auth';

export default function SignUpPage() {
return (
<div className='flex min-h-svh w-full items-center justify-center p-6 md:p-10'>
<div className='w-full max-w-md'>
<Card>
<CardHeader>
<CardTitle className='text-2xl'>Sign Up</CardTitle>
<CardDescription>Enter your email below to create a new account</CardDescription>
</CardHeader>
<CardContent>
<SignUpForm />
</CardContent>
</Card>
</div>
</div>
);
}
40 changes: 38 additions & 2 deletions app/(shop)/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
import Link from 'next/link';

import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { getUser } from '@/lib/auth-server';

export const metadata = {
title: 'Home',
};

export default function HomePage() {
return <h2>HomePage</h2>;
export default async function HomePage() {
const user = await getUser();

if (!user) {
return (
<div>
<h1>Please log in to view your profile.</h1>
<p>If you don't have an account, please sign up.</p>
<p>
<Link href='/login'>Login</Link> | <Link href='/signup'>Sign Up</Link>
</p>
</div>
);
}

return (
<Card>
<CardHeader>
<CardTitle>User Profile</CardTitle>
</CardHeader>

<CardContent>
<div>
<p>
<strong>Name:</strong> {user.name}
</p>
<p>
<strong>Email:</strong> {user.email}
</p>
</div>
</CardContent>
</Card>
);
}
5 changes: 5 additions & 0 deletions app/api/auth/[...all]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { toNextJsHandler } from 'better-auth/next-js';

import { auth } from '@/lib/auth';

export const { POST, GET } = toNextJsHandler(auth);
5 changes: 1 addition & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export const metadata: Metadata = baseMetadata;

export default function RootLayout({ children }: Readonly<PropsWithChildren>) {
return (
<html
suppressHydrationWarning
lang='en'
className='h-full'>
<html suppressHydrationWarning>
<body
suppressHydrationWarning
className={cn(font.className)}>
Expand Down
34 changes: 12 additions & 22 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { withAuth } from '@kinde-oss/kinde-auth-nextjs/middleware';
import { NextRequest } from 'next/server';
import { getSessionCookie } from 'better-auth/cookies';
import { NextRequest, NextResponse } from 'next/server';

export default withAuth(
async function middleware(request: NextRequest) {
// console.log(request);
},
{ isReturnToCurrentPage: true },
);
export async function middleware(request: NextRequest) {
const sessionCookie = getSessionCookie(request);

if (!sessionCookie) {
return NextResponse.redirect(new URL('/sign-in', request.url));
}

return NextResponse.next();
}

export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - images
* - auth
* - login
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
* - homepage (represented with after beginning with a slash)
*/
'/((?!api|_next/static|_next/image|images|auth|login|favicon.ico|sitemap.xml|robots.txt|$).*)',
],
matcher: ['/customers/:path*', '/tickets/:path*'],
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
"@radix-ui/react-switch": "^1.2.2",
"@sentry/nextjs": "^8.42.0",
"@t3-oss/env-nextjs": "^0.11.1",
"better-auth": "^1.2.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.503.0",
"next": "^15.3.0",
"next-themes": "^0.4.1",
"next-safe-action": "^7.10.4",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"react-hook-form": "^7.54.1",
Expand All @@ -44,16 +46,16 @@
"zod": "^3.24.1"
},
"devDependencies": {
"@next/eslint-plugin-next": "^15.3.0",
"@eslint/eslintrc": "^3.3.1",
"@next/eslint-plugin-next": "^15.3.0",
"@prisma/client": "^6.6.0",
"@tailwindcss/postcss": "^4.1.4",
"@tailwindcss/typography": "^0.5.15",
"@types/node": "^22.10.1",
"@types/react": "^19.1.0",
"@types/react-dom": "^19.1.0",
"@typescript-eslint/parser": "^8.31.0",
"@typescript-eslint/eslint-plugin": "^8.31.0",
"@typescript-eslint/parser": "^8.31.0",
"dotenv": "^16.5.0",
"eslint": "^9.25.1",
"eslint-config-next": "^15.3.0",
Expand Down
Loading