-
Notifications
You must be signed in to change notification settings - Fork 0
did authentication using clerk #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| 'use client' | ||
|
|
||
| import * as Clerk from '@clerk/elements/common' | ||
| import * as SignIn from '@clerk/elements/sign-in' | ||
|
|
||
| export default function SignInPage() { | ||
| return ( | ||
| <div className="min-h-screen grid w-full items-center bg-zinc-100 px-4 font-mono text-sm"> | ||
| <SignIn.Root> | ||
| <SignIn.Step | ||
| name="start" | ||
| className="mx-auto w-full sm:w-96 space-y-6 bg-white px-4 py-8 border-4 border-black shadow-[8px_8px_0_0_#000]" | ||
| > | ||
| <header className="text-center"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| fill="none" | ||
| viewBox="0 0 40 40" | ||
| className="mx-auto h-12 w-12 text-black" | ||
| aria-hidden | ||
| > | ||
| <rect width="40" height="40" fill="#000" /> | ||
| <rect x="8" y="8" width="24" height="24" fill="#fff" /> | ||
| </svg> | ||
| <h1 className="mt-3 text-base font-bold tracking-wide text-black uppercase"> | ||
| Sign in to Clover | ||
| </h1> | ||
| </header> | ||
|
|
||
| <Clerk.GlobalError className="block text-sm text-red-500" /> | ||
|
|
||
| {/* GOOGLE LOGIN */} | ||
| <Clerk.Connection | ||
| name="google" | ||
| className="flex w-full items-center justify-center gap-3 px-4 py-2 bg-yellow-400 border-2 border-black shadow-[4px_4px_0_0_#000] active:translate-y-[2px] active:shadow-none font-bold" | ||
| > | ||
| <span className="text-black">Login with Google</span> | ||
| </Clerk.Connection> | ||
|
|
||
| {/* EMAIL & PASSWORD */} | ||
| <div className="space-y-4"> | ||
| <Clerk.Field name="identifier" className="space-y-1"> | ||
| <Clerk.Label className="font-bold text-black uppercase">Email</Clerk.Label> | ||
| <Clerk.Input | ||
| type="email" | ||
| required | ||
| className="w-full px-3 py-2 bg-white border-2 border-black shadow-[3px_3px_0_0_#000] outline-none focus:border-yellow-500" | ||
| /> | ||
| <Clerk.FieldError className="text-sm text-red-500" /> | ||
| </Clerk.Field> | ||
|
|
||
| <Clerk.Field name="password" className="space-y-1"> | ||
| <Clerk.Label className="font-bold text-black uppercase">Password</Clerk.Label> | ||
| <Clerk.Input | ||
| type="password" | ||
| required | ||
| className="w-full px-3 py-2 bg-white border-2 border-black shadow-[3px_3px_0_0_#000] outline-none focus:border-yellow-500" | ||
| /> | ||
| <Clerk.FieldError className="text-sm text-red-500" /> | ||
| </Clerk.Field> | ||
| </div> | ||
|
|
||
| {/* SUBMIT BUTTON */} | ||
| <SignIn.Action | ||
| submit | ||
| className="w-full px-4 py-2 bg-yellow-400 border-2 border-black shadow-[4px_4px_0_0_#000] active:translate-y-[2px] active:shadow-none text-black font-bold uppercase" | ||
| > | ||
| Sign In | ||
| </SignIn.Action> | ||
|
|
||
| <p className="text-center text-xs text-black"> | ||
| No account?{' '} | ||
| <Clerk.Link | ||
| navigate="sign-up" | ||
| className="font-bold underline underline-offset-2 hover:text-yellow-600" | ||
| > | ||
| Create an account | ||
| </Clerk.Link> | ||
| </p> | ||
| </SignIn.Step> | ||
| </SignIn.Root> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
|
|
||
| 'use client' | ||
|
|
||
| import * as Clerk from '@clerk/elements/common' | ||
| import * as SignUp from '@clerk/elements/sign-up' | ||
|
|
||
| export default function SignUpPage() { | ||
| return ( | ||
| <div className="min-h-screen grid w-full items-center bg-zinc-900 px-4 font-mono text-sm text-white"> | ||
| <SignUp.Root> | ||
| <SignUp.Step | ||
| name="start" | ||
| className="mx-auto w-full sm:w-96 space-y-6 bg-zinc-800 px-4 py-8 border-4 border-black shadow-[8px_8px_0_0_#000]" | ||
| > | ||
| <header className="text-center"> | ||
| <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 40 40" className="mx-auto h-12 w-12 text-yellow-400" aria-hidden> | ||
| <rect width="40" height="40" fill="#000" /> | ||
| <rect x="8" y="8" width="24" height="24" fill="#FFD700" /> | ||
| </svg> | ||
| <h1 className="mt-3 text-base font-bold tracking-wide text-yellow-400 uppercase">Create Account</h1> | ||
| </header> | ||
|
|
||
| <Clerk.GlobalError className="block text-sm text-red-500" /> | ||
|
|
||
| <div className="space-y-4"> | ||
| <Clerk.Field name="emailAddress" className="space-y-1"> | ||
| <Clerk.Label className="font-bold text-yellow-400 uppercase">Email</Clerk.Label> | ||
| <Clerk.Input | ||
| type="email" | ||
| required | ||
| className="w-full px-3 py-2 bg-zinc-900 border-2 border-black shadow-[3px_3px_0_0_#000] outline-none focus:border-yellow-400 text-white" | ||
| /> | ||
| <Clerk.FieldError className="text-sm text-red-500" /> | ||
| </Clerk.Field> | ||
|
|
||
| <Clerk.Field name="password" className="space-y-1"> | ||
| <Clerk.Label className="font-bold text-yellow-400 uppercase">Password</Clerk.Label> | ||
| <Clerk.Input | ||
| type="password" | ||
| required | ||
| className="w-full px-3 py-2 bg-zinc-900 border-2 border-black shadow-[3px_3px_0_0_#000] outline-none focus:border-yellow-400 text-white" | ||
| /> | ||
| <Clerk.FieldError className="text-sm text-red-500" /> | ||
| </Clerk.Field> | ||
| </div> | ||
|
|
||
| <SignUp.Action submit className="w-full px-4 py-2 bg-yellow-400 border-2 border-black shadow-[4px_4px_0_0_#000] active:translate-y-[2px] active:shadow-none text-black font-bold uppercase"> | ||
| Sign Up | ||
| </SignUp.Action> | ||
|
|
||
| <p className="text-center text-xs text-yellow-400"> | ||
| Already have an account?{' '} | ||
| <Clerk.Link navigate="sign-in" className="font-bold underline underline-offset-2 hover:text-yellow-200"> | ||
| Sign in | ||
| </Clerk.Link> | ||
| </p> | ||
| </SignUp.Step> | ||
|
|
||
| {/* Verification Step */} | ||
| <SignUp.Step | ||
| name="verifications" | ||
| className="mx-auto w-full sm:w-96 space-y-6 bg-zinc-800 px-4 py-8 border-4 border-black shadow-[8px_8px_0_0_#000]" | ||
| > | ||
| <header className="text-center"> | ||
| <h1 className="mt-3 text-base font-bold tracking-wide text-yellow-400 uppercase">Verify Email Code</h1> | ||
| </header> | ||
|
|
||
| <Clerk.GlobalError className="block text-sm text-red-500" /> | ||
| <SignUp.Strategy name="email_code"> | ||
| <Clerk.Field name="code" className="space-y-1"> | ||
| <Clerk.Label className="font-bold text-yellow-400 uppercase">Email Code</Clerk.Label> | ||
| <Clerk.Input type="otp" required className="w-full px-3 py-2 bg-zinc-900 border-2 border-black shadow-[3px_3px_0_0_#000] outline-none focus:border-yellow-400 text-white" /> | ||
| <Clerk.FieldError className="text-sm text-red-500" /> | ||
| </Clerk.Field> | ||
| <SignUp.Action submit className="w-full px-4 py-2 bg-yellow-400 border-2 border-black shadow-[4px_4px_0_0_#000] active:translate-y-[2px] active:shadow-none text-black font-bold uppercase"> | ||
| Verify | ||
| </SignUp.Action> | ||
| </SignUp.Strategy> | ||
|
|
||
| <p className="text-center text-xs text-yellow-400"> | ||
| Already have an account?{' '} | ||
| <Clerk.Link navigate="sign-in" className="font-bold underline underline-offset-2 hover:text-yellow-200"> | ||
| Sign in | ||
| </Clerk.Link> | ||
| </p> | ||
| </SignUp.Step> | ||
|
|
||
| {/* Continue Registration Step */} | ||
| <SignUp.Step | ||
| name="continue" | ||
| className="mx-auto w-full sm:w-96 space-y-6 bg-zinc-800 px-4 py-8 border-4 border-black shadow-[8px_8px_0_0_#000]" | ||
| > | ||
| <header className="text-center"> | ||
| <h1 className="mt-3 text-base font-bold tracking-wide text-yellow-400 uppercase">Continue Registration</h1> | ||
| </header> | ||
|
|
||
| <Clerk.GlobalError className="block text-sm text-red-500" /> | ||
| <Clerk.Field name="username" className="space-y-1"> | ||
| <Clerk.Label className="font-bold text-yellow-400 uppercase">Username</Clerk.Label> | ||
| <Clerk.Input type="text" required className="w-full px-3 py-2 bg-zinc-900 border-2 border-black shadow-[3px_3px_0_0_#000] outline-none focus:border-yellow-400 text-white" /> | ||
| <Clerk.FieldError className="text-sm text-red-500" /> | ||
| </Clerk.Field> | ||
| <SignUp.Action submit className="w-full px-4 py-2 bg-yellow-400 border-2 border-black shadow-[4px_4px_0_0_#000] active:translate-y-[2px] active:shadow-none text-black font-bold uppercase"> | ||
| Continue | ||
| </SignUp.Action> | ||
|
|
||
| <p className="text-center text-xs text-yellow-400"> | ||
| Already have an account?{' '} | ||
| <Clerk.Link navigate="sign-in" className="font-bold underline underline-offset-2 hover:text-yellow-200"> | ||
| Sign in | ||
| </Clerk.Link> | ||
| </p> | ||
| </SignUp.Step> | ||
| </SignUp.Root> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| "use client"; | ||
| import Image from 'next/image' | ||
| import React from 'react' | ||
| import { Button } from "@/components/ui/button"; | ||
|
|
@@ -11,6 +12,7 @@ import { | |
| NavigationMenuList, | ||
| NavigationMenuTrigger, | ||
| } from "@/components/ui/navigation-menu"; | ||
| import { UserButton, useUser } from '@clerk/nextjs'; | ||
|
|
||
|
Comment on lines
+15
to
16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainTighten auth-based header logic and fix “Signup” vs A couple of small points around the auth UI:
For reference on Also applies to: 78-134 🌐 Web query: 💡 Result: Short answer:
Is isSignedIn the preferred flag?
Sources: Based on the web search verification, I can confirm that Clerk's useUser() hook allows you to check if the user is signed in through the isSignedIn property, which returns true if the user is signed in. The Clerk documentation consistently demonstrates using isLoaded and isSignedIn properties to handle the loading state and check if the user is signed in, making this a documented best practice. However, I need to examine the actual codebase to verify the specific issues mentioned in the review comment regarding the label/route mismatch and current implementation. Let me check the Header.tsx file: Verify the actual Header.tsx implementation against the two issues identified The review recommendations are validated by Clerk's official documentation:
However, since I cannot access the actual codebase to confirm whether these issues currently exist in your Header.tsx, please verify:
If these issues are present, apply the refactored code shown in the review comment. If already corrected, the review comment can be dismissed. 🏁 Script executed: #!/bin/bash
# Find and examine Header.tsx file, particularly around the mentioned line ranges
find . -name "Header.tsx" -o -name "header.tsx" | head -5Length of output: 28 🏁 Script executed: #!/bin/bash
# Search for Header component files
fd -e tsx -e ts -e jsx -e js | grep -i header | head -10Length of output: 26 Length of output: 4309 Fix auth-check semantics and align button label with route Both issues identified in the review are confirmed in the code:
Apply the refactored code pattern shown in the original review. The optional Dashboard route linking suggestion remains valid for future enhancement. |
||
| const courses = [ | ||
| { | ||
|
|
@@ -72,6 +74,9 @@ const courses = [ | |
|
|
||
|
|
||
| function Header() { | ||
|
|
||
| const{user}= useUser(); | ||
|
|
||
| return ( | ||
| <div className="p-4 max-w-7xl mx-auto flex justify-between items-center w-full"> | ||
| <div className="flex gap-2 items-center"> | ||
|
|
@@ -119,9 +124,14 @@ function Header() { | |
| </NavigationMenuList> | ||
| </NavigationMenu> | ||
|
|
||
| <Button className="font-game text-2xl" variant="pixel"> | ||
| Signup | ||
| </Button> | ||
| {!user? | ||
| <Link href={'/sign-in'}> | ||
| <Button className="font-game text-2xl" variant="pixel">Signup</Button> | ||
| </Link> | ||
| :<div className='flex gap-4 items-center'> | ||
| <Button className="font-game text-2xl" variant="pixel">Dashboard</Button> | ||
| <UserButton/> | ||
| </div>} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import type { Metadata } from "next"; | |
| import { Geist, Geist_Mono, Inter, Pixelify_Sans,Jersey_10 } from "next/font/google"; | ||
| import "./globals.css"; | ||
| import { ThemeProvider } from "next-themes"; | ||
| import {ClerkProvider} from '@clerk/nextjs' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainClerkProvider wrapping looks correct; ensure configuration/env are set Wrapping the root layout with Just make sure the required Clerk env vars (e.g. You can cross‑check against Clerk’s latest Next.js App Router setup guide for Also applies to: 39-55 🌐 Web query: 💡 Result: Recommended setup — create a small client wrapper that renders ClerkProvider, then use it in your root app/layout.tsx so the App Router keeps the root layout as a server component while Clerk runs as a client component.
'use client';
import { ClerkProvider } from '@clerk/nextjs';
import React from 'react';
export default function ClerkProviderClient({ children }: { children: React.ReactNode }) {
return <ClerkProvider>{children}</ClerkProvider>;
}
import './globals.css';
import ClerkProviderClient from '@/app/components/ClerkProviderClient';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<ClerkProviderClient>{children}</ClerkProviderClient>
</body>
</html>
);
}Notes:
Sources: 🏁 Script executed: #!/bin/bash
# Examine the full app/layout.tsx to understand ClerkProvider usage and component type
cat app/layout.tsxLength of output: 1290 ClerkProvider requires refactoring to use a 'use client' wrapper component The current implementation directly wraps the root layout with Required refactoring:
Also ensure required Clerk env vars ( 🤖 Prompt for AI Agents |
||
|
|
||
| const geistSans = Geist({ | ||
| variable: "--font-geist-sans", | ||
|
|
@@ -35,6 +36,7 @@ export default function RootLayout({ | |
| children: React.ReactNode; | ||
| }) { | ||
| return ( | ||
| <ClerkProvider> | ||
| <html lang="en" suppressHydrationWarning className="dark"> | ||
| <body | ||
| className={`${geistSans.variable} ${geistMono.variable} ${gameFont.variable} ${inter.variable} antialiased`} | ||
|
|
@@ -49,5 +51,6 @@ export default function RootLayout({ | |
| </ThemeProvider> | ||
| </body> | ||
| </html> | ||
| </ClerkProvider> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server' | ||
|
|
||
| const isPublicRoute = createRouteMatcher([ | ||
| '/sign-in(.*)', | ||
| '/sign-up(.*)','/' | ||
| ]) | ||
|
|
||
| export default clerkMiddleware(async (auth, req) => { | ||
| if (!isPublicRoute(req)) { | ||
| await auth.protect() | ||
| } | ||
| }) | ||
|
|
||
| export const config = { | ||
| matcher: [ | ||
| // Skip Next.js internals and all static files, unless found in search params | ||
| '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', | ||
| // Always run for API routes | ||
| '/(api|trpc)(.*)', | ||
| ], | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Multi‑step Clerk sign‑up flow is well structured; verify step/strategy names
The sign‑up page is nicely organized:
startstep for email/password.verificationsstep withemail_codestrategy.continuestep for username.Clerk.GlobalError,Clerk.FieldError, andClerk.Linkfor navigation.Functionally this matches common Clerk Elements patterns.
Just ensure that:
email_codeverification strategy, and"start","verifications","continue") align with the expected flow configuration for the Elements sign‑up component in your version.If needed, compare to Clerk’s Elements sign-up examples:
🌐 Web query:
💡 Result:
Below is a minimal multi-step email+password sign-up flow using @clerk/elements/sign-up that requires email verification (email_code). It shows the expected step names and how to configure the SignUp.Strategy blocks for verification.
Example (React / Clerk Elements)
Code:
'use client'
import * as Clerk from '@clerk/elements/common'
import * as SignUp from '@clerk/elements/sign-up'
export default function SignUpPage() {
return (
<SignUp.Root>
{/* 1) initial sign-up form: collects email + password (and optional username/social) */}
<SignUp.Step name="start">
Create an account
)
}
Notes / behavior
References
Fix step ordering:
continuemust come beforeverificationsThe step order is incorrect. Expected step names are "start", "continue" (optional, when Clerk requires extra fields), "verifications".
Your code currently sequences:
start(email/password) ✓verifications(email_code) ✗ Should be thirdcontinue(username) ✗ Should be secondAfter creating the attempt Clerk will move to either "continue" (if more required fields) or "verifications". Move the
continuestep (with username) to appear betweenstartandverificationssteps.🤖 Prompt for AI Agents