Skip to content

Commit

Permalink
fix: authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
binglekruger committed Jan 16, 2025
1 parent f3652f8 commit e372120
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 109 deletions.
15 changes: 15 additions & 0 deletions ntc-web/app/AuthLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client'

import { usePathname } from 'next/navigation'
import LayoutClient from './LayoutClient'

export default function AuthLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
const isAuthPage = pathname === '/sign-in' || pathname === '/sign-up'

if (isAuthPage) {
return children
}

return <LayoutClient>{children}</LayoutClient>
}
9 changes: 3 additions & 6 deletions ntc-web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import './globals.css'
import LayoutClient from './LayoutClient'
import {
ClerkProvider,
SignInButton,
SignedIn,
SignedOut,
UserButton
} from '@clerk/nextjs'
import AuthLayout from './AuthLayout' // Add this import

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -21,9 +18,9 @@ export default function RootLayout({
<html lang="en" suppressHydrationWarning>
<body className={inter.className} suppressHydrationWarning>
<div id="app-root">
<LayoutClient>
<AuthLayout>
{children}
</LayoutClient>
</AuthLayout>
</div>
</body>
</html>
Expand Down
61 changes: 61 additions & 0 deletions ntc-web/app/sign-in/[[...sign-in]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use client';

import { SignIn } from '@clerk/nextjs';
import { useRouter, useSearchParams } from 'next/navigation';
import Image from 'next/image';

export default function SignInPage() {
const router = useRouter();
const searchParams = useSearchParams();
const redirectUrl = searchParams.get('redirect_url') || '/dashboard';
const currentYear = new Date().getFullYear();

return (
<div className="min-h-screen flex flex-col">
<div className="flex-grow flex items-center justify-center bg-gray-50">
<div className="w-full max-w-md">
<div className="bg-white py-8 px-6 shadow-sm rounded-lg">
<div className="mb-6 text-center">
<div className="mb-4 flex justify-center">
<div className="w-80 h-80 relative">
<Image src="/logo.png" alt="Logo" fill className="object-contain" priority />
</div>
</div>
<h2 className="text-2xl font-bold text-gray-900">Nautilus MVP Sign In</h2>
</div>
<SignIn
afterSignInUrl={redirectUrl}
appearance={{
elements: {
formButtonPrimary: 'bg-blue-600 hover:bg-blue-700 text-sm normal-case',
card: 'shadow-none',
headerTitle: 'hidden',
headerSubtitle: 'hidden',
socialButtonsBlockButton: 'text-gray-600 hover:bg-gray-100 border border-gray-300',
footerActionLink: 'text-blue-600 hover:text-blue-700 font-semibold',
},
}}
/>
</div>
</div>
</div>

<footer className="py-6 bg-gray-50">
<div className="text-center text-sm text-gray-600">
<div className="mb-2">
Copyright © {currentYear}. <span className="font-semibold">Nautilus</span> All rights reserved.
</div>
<div>
<a href="#" className="font-semibold hover:text-gray-900 transition-colors">
Privacy
</a>
<span className="mx-2 font-light">and</span>
<a href="#" className="font-semibold hover:text-gray-900 transition-colors">
Terms of Use
</a>
</div>
</div>
</footer>
</div>
);
}
76 changes: 76 additions & 0 deletions ntc-web/app/sign-up/[[...sign-up]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use client';

import { SignUp } from "@clerk/nextjs";
import Image from "next/image";

export default function SignUpPage() {
const currentYear = new Date().getFullYear();

return (
<div className="min-h-screen flex flex-col">
<div className="flex-grow flex items-center justify-center bg-gray-50">
<div className="w-full max-w-md">
<div className="bg-white py-8 px-6 shadow-sm rounded-lg">
<div className="mb-6 text-center">
<div className="mb-4 flex justify-center">
<div className="w-80 h-80 relative">
<Image
src="/logo.png"
alt="Logo"
fill
className="object-contain"
priority
/>
</div>
</div>
<h2 className="text-2xl font-bold text-gray-900">Create Account</h2>
</div>

<SignUp
appearance={{
elements: {
formButtonPrimary:
"bg-blue-600 hover:bg-blue-700 text-sm normal-case",
card: "shadow-none",
headerTitle: "hidden",
headerSubtitle: "hidden",
socialButtonsBlockButton:
"text-gray-600 hover:bg-gray-100 border border-gray-300",
footerActionLink:
"text-blue-600 hover:text-blue-700 font-semibold"
}
}}
/>

<div className="mt-6 text-center text-sm">
<span className="text-gray-600">Already have an account? </span>
<a
href="/sign-in"
className="text-blue-600 hover:text-blue-700 font-semibold"
>
Sign In
</a>
</div>
</div>
</div>
</div>

<footer className="py-6 bg-gray-50">
<div className="text-center text-sm text-gray-600">
<div className="mb-2">
Copyright © {currentYear}. <span className="font-semibold">Nautilus</span> All rights reserved.
</div>
<div>
<a href="#" className="font-semibold hover:text-gray-900 transition-colors">
Privacy
</a>
<span className="mx-2 font-light">and</span>
<a href="#" className="font-semibold hover:text-gray-900 transition-colors">
Terms of Use
</a>
</div>
</div>
</footer>
</div>
);
}
12 changes: 9 additions & 3 deletions ntc-web/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { clerkMiddleware } from "@clerk/nextjs/server";
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

export default clerkMiddleware();
const isPublicRoute = createRouteMatcher(['/sign-in(.*)', '/sign-up(.*)'])

export default clerkMiddleware(async (auth, request) => {
if (!isPublicRoute(request)) {
await auth.protect()
}
})

export const config = {
matcher: [
Expand All @@ -9,4 +15,4 @@ export const config = {
// Always run for API routes
'/(api|trpc)(.*)',
],
};
}
47 changes: 0 additions & 47 deletions ntc-web/sign-in/[[...sign-in]]/page.tsx

This file was deleted.

53 changes: 0 additions & 53 deletions ntc-web/sign-up/[[...sign-up]]/page.tsx

This file was deleted.

0 comments on commit e372120

Please sign in to comment.