Authentication Setup Guide
Visit Clerk Dashboard
Create new application
Select Next.js framework
Navigate to User & Authentication > Email, Phone, Username
Enable:
Email addresses (Required, Used for sign-in, Verify at sign-up)
Phone numbers
Usernames
Name (First and Last)
Email verification link
Email verification code
Go to GitHub Developer Settings
Create OAuth App:
Name: whoami.page
Homepage URL: http://localhost:3000
Authorization callback URL: [Clerk Callback URL]
Copy credentials to Clerk Dashboard
Visit Google Cloud Console
Create/select project
Enable OAuth 2.0:
Application type: Web application
Authorized redirect URIs: [Clerk Callback URLs]
Copy credentials to Clerk Dashboard
Add Redirect URL: localhost:3000/sso-callback
Production URLs format: https://your-domain.com/sso-callback
Go to Sessions
Edit token custom claims:
{
"metadata" : " {{user.public_metadata}}"
}
npm install @clerk/nextjs @clerk/themes
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = pk_test_...
CLERK_SECRET_KEY = sk_test_...
// app/layout.tsx
import { ClerkProvider } from '@clerk/nextjs' ;
export default function RootLayout ( {
children,
} : {
children : React . ReactNode ;
} ) {
return (
< ClerkProvider >
{ children}
< / ClerkProvider>
) ;
}
// middleware.ts
import { authMiddleware } from "@clerk/nextjs" ;
export default authMiddleware ( {
publicRoutes : [ "/" , "/api/webhook/clerk" , "/sso-callback" ] ,
ignoredRoutes : [ "/api/webhook/clerk" ]
} ) ;
export const config = {
matcher : [ "/((?!.*\\..*|_next).*)" , "/" , "/(api|trpc)(.*)" ] ,
} ;
// components/auth/sign-in.tsx
import { SignIn } from "@clerk/nextjs" ;
export default function SignInPage ( ) {
return (
< SignIn
appearance = { {
elements : {
formButtonPrimary : 'bg-primary hover:bg-primary/80' ,
socialButtonsIconButton : 'border-border bg-background hover:bg-accent' ,
} ,
} }
/ >
) ;
}
// app/sso-callback/page.tsx
import { SignedIn , SignedOut } from "@clerk/nextjs" ;
import { redirect } from "next/navigation" ;
export default function SSOCallback ( ) {
return (
< >
< SignedIn >
{ redirect ( '/' ) }
< / SignedIn>
< SignedOut >
{ redirect ( '/sign-in' ) }
< / SignedOut>
< / >
) ;
}
Verify callback URLs match exactly
Check environment variables
Confirm OAuth provider configuration
Clear browser cache/cookies
Verify custom claims syntax
Check token expiration settings